New function CollTransfer. Change CollAt and CollAtUnchecked to take a const

Collection pointer instead of just a Collection pointer. This makes more
sense, since the functions do not change the collection.


git-svn-id: svn://svn.cc65.org/cc65/trunk@5224 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2011-08-19 11:01:01 +00:00
parent 307b8d88c3
commit 189a9bfb38
2 changed files with 31 additions and 5 deletions

View File

@@ -167,7 +167,7 @@ void CollAppend (Collection* C, void* Item)
#if !defined(HAVE_INLINE)
void* CollAt (Collection* C, unsigned Index)
void* CollAt (const Collection* C, unsigned Index)
/* Return the item at the given index */
{
/* Check the index */
@@ -438,6 +438,26 @@ static void QuickSort (Collection* C, int Lo, int Hi,
void CollTransfer (Collection* Dest, const Collection* Source)
/* Transfer all items from Source to Dest. Anything already in Dest is left
* untouched. The items in Source are not changed and are therefore in both
* Collections on return.
*/
{
/* Be sure there's enough room in Dest */
CollGrow (Dest, Dest->Count + Source->Count);
/* Copy the items */
memcpy (Dest->Items + Dest->Count,
Source->Items,
Source->Count * sizeof (Source->Items[0]));
/* Bump the counter */
Dest->Count += Source->Count;
}
void CollSort (Collection* C,
int (*Compare) (void*, const void*, const void*),
void* Data)