1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-19 06:31:31 +00:00

Allow static initialization of collections

git-svn-id: svn://svn.cc65.org/cc65/trunk@308 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2000-09-01 14:48:04 +00:00
parent 0d7763cedb
commit d62e48f14a
2 changed files with 9 additions and 2 deletions

View File

@ -114,7 +114,11 @@ void CollInsert (Collection* C, void* Item, unsigned Index)
if (C->Count >= C->Size) { if (C->Count >= C->Size) {
/* Must grow */ /* Must grow */
void** NewItems; void** NewItems;
if (C->Size > 0) {
C->Size *= 2; C->Size *= 2;
} else {
C->Size = 8;
}
NewItems = xmalloc (C->Size * sizeof (void*)); NewItems = xmalloc (C->Size * sizeof (void*));
memcpy (NewItems, C->Items, C->Count * sizeof (void*)); memcpy (NewItems, C->Items, C->Count * sizeof (void*));
xfree (C->Items); xfree (C->Items);

View File

@ -56,6 +56,9 @@ struct Collection {
void** Items; /* Array with dynamic size */ void** Items; /* Array with dynamic size */
}; };
/* Initializer for static collections */
#define STATIC_COLLECTION_INITIALIZER { 0, 0, 0 }
/*****************************************************************************/ /*****************************************************************************/
@ -73,7 +76,7 @@ void DoneCollection (Collection* C);
*/ */
Collection* NewCollection (void); Collection* NewCollection (void);
/* Create and return a new collection with the given initial size */ /* Create and return a new collection */
void FreeCollection (Collection* C); void FreeCollection (Collection* C);
/* Free a collection */ /* Free a collection */