From: uz Date: Fri, 19 Aug 2011 11:01:01 +0000 (+0000) Subject: New function CollTransfer. Change CollAt and CollAtUnchecked to take a const X-Git-Tag: V2.13.3~238 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=189a9bfb38a64ea80a6f452cde74ebcc6fc596e6;p=cc65 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 --- diff --git a/src/common/coll.c b/src/common/coll.c index 1a0b9afc7..a75dc7bed 100644 --- a/src/common/coll.c +++ b/src/common/coll.c @@ -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) diff --git a/src/common/coll.h b/src/common/coll.h index 503b9bbdd..f53ab6893 100644 --- a/src/common/coll.h +++ b/src/common/coll.h @@ -122,7 +122,7 @@ void CollAppend (Collection* C, void* Item); #endif #if defined(HAVE_INLINE) -INLINE void* CollAt (Collection* C, unsigned Index) +INLINE void* CollAt (const Collection* C, unsigned Index) /* Return the item at the given index */ { /* Check the index */ @@ -132,19 +132,19 @@ INLINE void* CollAt (Collection* C, unsigned Index) return C->Items[Index]; } #else -void* CollAt (Collection* C, unsigned Index); +void* CollAt (const Collection* C, unsigned Index); /* Return the item at the given index */ #endif #if defined(HAVE_INLINE) -INLINE void* CollAtUnchecked (Collection* C, unsigned Index) +INLINE void* CollAtUnchecked (const Collection* C, unsigned Index) /* Return the item at the given index */ { /* Return the element */ return C->Items[Index]; } #else -# define CollAtUnchecked(C, Index) ((C)->Items[(Index)]) +# define CollAtUnchecked(C, Index) ((C)->Items[(Index)]) #endif #if defined(HAVE_INLINE) @@ -274,6 +274,12 @@ void CollMoveMultiple (Collection* C, unsigned Start, unsigned Count, unsigned T * to higher indices. */ +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. + */ + void CollSort (Collection* C, int (*Compare) (void*, const void*, const void*), void* Data);