Fixed problems with the inline macros
git-svn-id: svn://svn.cc65.org/cc65/trunk@1040 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -116,22 +116,22 @@ void CollInsert (Collection* C, void* Item, unsigned Index)
|
||||
|
||||
/* Grow the array if necessary */
|
||||
if (C->Count >= C->Size) {
|
||||
/* Must grow */
|
||||
/* Must grow */
|
||||
void** NewItems;
|
||||
if (C->Size > 0) {
|
||||
C->Size *= 2;
|
||||
} else {
|
||||
C->Size = 8;
|
||||
}
|
||||
NewItems = xmalloc (C->Size * sizeof (void*));
|
||||
memcpy (NewItems, C->Items, C->Count * sizeof (void*));
|
||||
xfree (C->Items);
|
||||
C->Items = NewItems;
|
||||
if (C->Size > 0) {
|
||||
C->Size *= 2;
|
||||
} else {
|
||||
C->Size = 8;
|
||||
}
|
||||
NewItems = xmalloc (C->Size * sizeof (void*));
|
||||
memcpy (NewItems, C->Items, C->Count * sizeof (void*));
|
||||
xfree (C->Items);
|
||||
C->Items = NewItems;
|
||||
}
|
||||
|
||||
/* Move the existing elements if needed */
|
||||
if (C->Count != Index) {
|
||||
memmove (C->Items+Index+1, C->Items+Index, (C->Count-Index) * sizeof (void*));
|
||||
memmove (C->Items+Index+1, C->Items+Index, (C->Count-Index) * sizeof (void*));
|
||||
}
|
||||
++C->Count;
|
||||
|
||||
@@ -141,6 +141,89 @@ void CollInsert (Collection* C, void* Item, unsigned Index)
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void CollAppend (Collection* C, void* Item)
|
||||
/* Append an item to the end of the collection */
|
||||
{
|
||||
/* Insert the item at the end of the current list */
|
||||
CollInsert (C, Item, C->Count);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void* CollAt (Collection* C, unsigned Index)
|
||||
/* Return the item at the given index */
|
||||
{
|
||||
/* Check the index */
|
||||
PRECONDITION (Index < C->Count);
|
||||
|
||||
/* Return the element */
|
||||
return C->Items[Index];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
const void* CollConstAt (const Collection* C, unsigned Index)
|
||||
/* Return the item at the given index */
|
||||
{
|
||||
/* Check the index */
|
||||
PRECONDITION (Index < C->Count);
|
||||
|
||||
/* Return the element */
|
||||
return C->Items[Index];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void* CollLast (Collection* C)
|
||||
/* Return the last item in a collection */
|
||||
{
|
||||
/* We must have at least one entry */
|
||||
PRECONDITION (C->Count > 0);
|
||||
|
||||
/* Return the element */
|
||||
return C->Items[C->Count-1];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
const void* CollConstLast (const Collection* C)
|
||||
/* Return the last item in a collection */
|
||||
{
|
||||
/* We must have at least one entry */
|
||||
PRECONDITION (C->Count > 0);
|
||||
|
||||
/* Return the element */
|
||||
return C->Items[C->Count-1];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void* CollPop (Collection* C)
|
||||
/* Remove the last segment from the stack and return it. Calls FAIL if the
|
||||
* collection is empty.
|
||||
*/
|
||||
{
|
||||
/* We must have at least one entry */
|
||||
PRECONDITION (C->Count > 0);
|
||||
|
||||
/* Return the element */
|
||||
return C->Items[--C->Count];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
int CollIndex (Collection* C, const void* Item)
|
||||
/* Return the index of the given item in the collection. Return -1 if the
|
||||
* item was not found in the collection.
|
||||
@@ -149,9 +232,9 @@ int CollIndex (Collection* C, const void* Item)
|
||||
/* Linear search */
|
||||
unsigned I;
|
||||
for (I = 0; I < C->Count; ++I) {
|
||||
if (Item == C->Items[I]) {
|
||||
/* Found */
|
||||
return (int)I;
|
||||
if (Item == C->Items[I]) {
|
||||
/* Found */
|
||||
return (int)I;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,6 +276,22 @@ void CollDeleteItem (Collection* C, const void* Item)
|
||||
|
||||
|
||||
|
||||
#if !defined(HAVE_INLINE)
|
||||
void CollReplace (Collection* C, void* Item, unsigned Index)
|
||||
/* Replace the item at the given position. The old item will not be freed,
|
||||
* just the pointer will get replaced.
|
||||
*/
|
||||
{
|
||||
/* Check the index */
|
||||
PRECONDITION (Index < C->Count);
|
||||
|
||||
/* Replace the item pointer */
|
||||
C->Items[Index] = Item;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
void CollMove (Collection* C, unsigned OldIndex, unsigned NewIndex)
|
||||
/* Move an item from one position in the collection to another. OldIndex
|
||||
* is the current position of the item, NewIndex is the new index after
|
||||
|
||||
Reference in New Issue
Block a user