Added g_(array|ptr_array|byte_array)_sized_new functions, that reserve a

2000-04-17  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

	* garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
	functions, that reserve a certain amount of memeory for the array
	at creation time to avoid reallocation. Fixes bug #6707 from
	Charles Kerr <ckerr@osserver1.nssl.noaa.gov>.
This commit is contained in:
Sebastian Wilhelmi 2000-04-17 10:59:46 +00:00 committed by Sebastian Wilhelmi
parent 8f02fac4ad
commit 03f9d485c1
12 changed files with 154 additions and 10 deletions

View File

@ -1,3 +1,14 @@
2000-04-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
functions, that reserve a certain amount of memeory for the array
at creation time to avoid reallocation. Fixes bug #6707 from
Charles Kerr <ckerr@osserver1.nssl.noaa.gov>.
* glib.h, gqueue.c, tests/queue-test.c (main): Renamed
g_queue_create to g_queue_new in conformance to all other GLib
data types.
2000-04-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* grand.c (g_rand_new): Fixed bug. Thanks to Marko Kreen

View File

@ -1,3 +1,14 @@
2000-04-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
functions, that reserve a certain amount of memeory for the array
at creation time to avoid reallocation. Fixes bug #6707 from
Charles Kerr <ckerr@osserver1.nssl.noaa.gov>.
* glib.h, gqueue.c, tests/queue-test.c (main): Renamed
g_queue_create to g_queue_new in conformance to all other GLib
data types.
2000-04-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* grand.c (g_rand_new): Fixed bug. Thanks to Marko Kreen

View File

@ -1,3 +1,14 @@
2000-04-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
functions, that reserve a certain amount of memeory for the array
at creation time to avoid reallocation. Fixes bug #6707 from
Charles Kerr <ckerr@osserver1.nssl.noaa.gov>.
* glib.h, gqueue.c, tests/queue-test.c (main): Renamed
g_queue_create to g_queue_new in conformance to all other GLib
data types.
2000-04-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* grand.c (g_rand_new): Fixed bug. Thanks to Marko Kreen

View File

@ -1,3 +1,14 @@
2000-04-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
functions, that reserve a certain amount of memeory for the array
at creation time to avoid reallocation. Fixes bug #6707 from
Charles Kerr <ckerr@osserver1.nssl.noaa.gov>.
* glib.h, gqueue.c, tests/queue-test.c (main): Renamed
g_queue_create to g_queue_new in conformance to all other GLib
data types.
2000-04-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* grand.c (g_rand_new): Fixed bug. Thanks to Marko Kreen

View File

@ -1,3 +1,14 @@
2000-04-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
functions, that reserve a certain amount of memeory for the array
at creation time to avoid reallocation. Fixes bug #6707 from
Charles Kerr <ckerr@osserver1.nssl.noaa.gov>.
* glib.h, gqueue.c, tests/queue-test.c (main): Renamed
g_queue_create to g_queue_new in conformance to all other GLib
data types.
2000-04-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* grand.c (g_rand_new): Fixed bug. Thanks to Marko Kreen

View File

@ -1,3 +1,14 @@
2000-04-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
functions, that reserve a certain amount of memeory for the array
at creation time to avoid reallocation. Fixes bug #6707 from
Charles Kerr <ckerr@osserver1.nssl.noaa.gov>.
* glib.h, gqueue.c, tests/queue-test.c (main): Renamed
g_queue_create to g_queue_new in conformance to all other GLib
data types.
2000-04-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* grand.c (g_rand_new): Fixed bug. Thanks to Marko Kreen

View File

@ -1,3 +1,14 @@
2000-04-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
functions, that reserve a certain amount of memeory for the array
at creation time to avoid reallocation. Fixes bug #6707 from
Charles Kerr <ckerr@osserver1.nssl.noaa.gov>.
* glib.h, gqueue.c, tests/queue-test.c (main): Renamed
g_queue_create to g_queue_new in conformance to all other GLib
data types.
2000-04-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* grand.c (g_rand_new): Fixed bug. Thanks to Marko Kreen

View File

@ -1,3 +1,14 @@
2000-04-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* garray.c, glib.h: Added g_(array|ptr_array|byte_array)_sized_new
functions, that reserve a certain amount of memeory for the array
at creation time to avoid reallocation. Fixes bug #6707 from
Charles Kerr <ckerr@osserver1.nssl.noaa.gov>.
* glib.h, gqueue.c, tests/queue-test.c (main): Renamed
g_queue_create to g_queue_new in conformance to all other GLib
data types.
2000-04-07 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* grand.c (g_rand_new): Fixed bug. Thanks to Marko Kreen

View File

@ -66,6 +66,14 @@ GArray*
g_array_new (gboolean zero_terminated,
gboolean clear,
guint elt_size)
{
return (GArray*) g_array_sized_new (zero_terminated, clear, elt_size, 0);
}
GArray* g_array_sized_new (gboolean zero_terminated,
gboolean clear,
guint elt_size,
guint reserved_size)
{
GRealArray *array;
@ -85,10 +93,10 @@ g_array_new (gboolean zero_terminated,
array->clear = (clear ? 1 : 0);
array->elt_size = elt_size;
if (array->zero_terminated)
if (array->zero_terminated || reserved_size != 0)
{
g_array_maybe_expand (array, 0);
g_array_elt_zero (array, 0, 1);
g_array_maybe_expand (array, reserved_size);
g_array_zero_terminate(array);
}
return (GArray*) array;
@ -282,6 +290,12 @@ G_LOCK_DEFINE_STATIC (ptr_array_mem_chunk);
GPtrArray*
g_ptr_array_new (void)
{
return g_ptr_array_sized_new (0);
}
GPtrArray*
g_ptr_array_sized_new (guint reserved_size)
{
GRealPtrArray *array;
@ -298,7 +312,10 @@ g_ptr_array_new (void)
array->len = 0;
array->alloc = 0;
return (GPtrArray*) array;
if (reserved_size != 0)
g_ptr_array_maybe_expand (array, reserved_size);
return (GPtrArray*) array;
}
void
@ -455,7 +472,12 @@ g_ptr_array_add (GPtrArray* farray,
GByteArray* g_byte_array_new (void)
{
return (GByteArray*) g_array_new (FALSE, FALSE, 1);
return (GByteArray*) g_array_sized_new (FALSE, FALSE, 1, 0);
}
GByteArray* g_byte_array_sized_new (guint reserved_size)
{
return (GByteArray*) g_array_sized_new (FALSE, FALSE, 1, reserved_size);
}
void g_byte_array_free (GByteArray *array,

6
glib.h
View File

@ -1891,6 +1891,10 @@ void g_string_sprintfa (GString *string,
GArray* g_array_new (gboolean zero_terminated,
gboolean clear,
guint element_size);
GArray* g_array_sized_new (gboolean zero_terminated,
gboolean clear,
guint element_size,
guint reserved_size);
void g_array_free (GArray *array,
gboolean free_segment);
GArray* g_array_append_vals (GArray *array,
@ -1917,6 +1921,7 @@ GArray* g_array_remove_index_fast (GArray *array,
*/
#define g_ptr_array_index(array,index) (array->pdata)[index]
GPtrArray* g_ptr_array_new (void);
GPtrArray* g_ptr_array_sized_new (guint reserved_size);
void g_ptr_array_free (GPtrArray *array,
gboolean free_seg);
void g_ptr_array_set_size (GPtrArray *array,
@ -1937,6 +1942,7 @@ void g_ptr_array_add (GPtrArray *array,
*/
GByteArray* g_byte_array_new (void);
GByteArray* g_byte_array_sized_new (guint reserved_size);
void g_byte_array_free (GByteArray *array,
gboolean free_segment);
GByteArray* g_byte_array_append (GByteArray *array,

View File

@ -66,6 +66,14 @@ GArray*
g_array_new (gboolean zero_terminated,
gboolean clear,
guint elt_size)
{
return (GArray*) g_array_sized_new (zero_terminated, clear, elt_size, 0);
}
GArray* g_array_sized_new (gboolean zero_terminated,
gboolean clear,
guint elt_size,
guint reserved_size)
{
GRealArray *array;
@ -85,10 +93,10 @@ g_array_new (gboolean zero_terminated,
array->clear = (clear ? 1 : 0);
array->elt_size = elt_size;
if (array->zero_terminated)
if (array->zero_terminated || reserved_size != 0)
{
g_array_maybe_expand (array, 0);
g_array_elt_zero (array, 0, 1);
g_array_maybe_expand (array, reserved_size);
g_array_zero_terminate(array);
}
return (GArray*) array;
@ -282,6 +290,12 @@ G_LOCK_DEFINE_STATIC (ptr_array_mem_chunk);
GPtrArray*
g_ptr_array_new (void)
{
return g_ptr_array_sized_new (0);
}
GPtrArray*
g_ptr_array_sized_new (guint reserved_size)
{
GRealPtrArray *array;
@ -298,7 +312,10 @@ g_ptr_array_new (void)
array->len = 0;
array->alloc = 0;
return (GPtrArray*) array;
if (reserved_size != 0)
g_ptr_array_maybe_expand (array, reserved_size);
return (GPtrArray*) array;
}
void
@ -455,7 +472,12 @@ g_ptr_array_add (GPtrArray* farray,
GByteArray* g_byte_array_new (void)
{
return (GByteArray*) g_array_new (FALSE, FALSE, 1);
return (GByteArray*) g_array_sized_new (FALSE, FALSE, 1, 0);
}
GByteArray* g_byte_array_sized_new (guint reserved_size)
{
return (GByteArray*) g_array_sized_new (FALSE, FALSE, 1, reserved_size);
}
void g_byte_array_free (GByteArray *array,

View File

@ -1891,6 +1891,10 @@ void g_string_sprintfa (GString *string,
GArray* g_array_new (gboolean zero_terminated,
gboolean clear,
guint element_size);
GArray* g_array_sized_new (gboolean zero_terminated,
gboolean clear,
guint element_size,
guint reserved_size);
void g_array_free (GArray *array,
gboolean free_segment);
GArray* g_array_append_vals (GArray *array,
@ -1917,6 +1921,7 @@ GArray* g_array_remove_index_fast (GArray *array,
*/
#define g_ptr_array_index(array,index) (array->pdata)[index]
GPtrArray* g_ptr_array_new (void);
GPtrArray* g_ptr_array_sized_new (guint reserved_size);
void g_ptr_array_free (GPtrArray *array,
gboolean free_seg);
void g_ptr_array_set_size (GPtrArray *array,
@ -1937,6 +1942,7 @@ void g_ptr_array_add (GPtrArray *array,
*/
GByteArray* g_byte_array_new (void);
GByteArray* g_byte_array_sized_new (guint reserved_size);
void g_byte_array_free (GByteArray *array,
gboolean free_segment);
GByteArray* g_byte_array_append (GByteArray *array,