Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Final last changes before releasing beta 2

-merge sort works and compiles correctly
-insertion sort missed function call in body
  • Loading branch information...
commit bf1038632ed9d4f98d7a72c5d96a7f73fe1e3719 1 parent 795bf97
@araker araker authored
View
3  AUTHORS
@@ -64,6 +64,9 @@ Contributors (alphabetically ordered):
* Nicky Weber (https://github.com/nickyEnjoysWoogoo):
Added convenience function to create a ccColor4F from color components
+
+* Nicolas Barrios (http://wefiends.com)
+ Fix for CCArray for ARC compatibility
* podhrask...@gmail.com
TouchDispatcher: correctly handles addition and removal of handlers when being inside a touch handler. patch
View
3  CHANGELOG
@@ -4,6 +4,7 @@ version 1.1-beta2 12-Mar-2012
Animation: Added new animation format that supports delays per frame and notifications per frame
Actions: Added ActionTargeted action. Useful to target other nodes from a sequence.
. [NEW] All: Code is compatible with ARC (issue #1199)
+. [NEW] CCArray: new sorting methods, replaceObjectAtIndex, isEqualToArray
. [NEW] ccFileUtiles: new iPad retina file extension (ipadhd)
. [NEW] DrawPrimitives: Added new functions, ccDrawRect, ccDrawSolidRect, ccDrawSolidPoly
. [NEW] DrawPrimitives: Added batch drawing of lines, ccDrawLines (issue #1081)
@@ -14,6 +15,8 @@ version 1.1-beta2 12-Mar-2012
. [NEW] Touchdispatcher: new implementation, supporting changing dispatchers based on (ranges) of properties, custom sorting and more (full list in online release notes)
. [NEW] Types: Added convenience function to create a ccColor4F from color components
. [FIX] Actions: incorrect behavior of CCRepeat
+. [FIX] CCArray: equalilty is tested by isEqual instead of comparing pointer addresses
+. [FIX] CCArray: CCARRAY_FOREACH macro is now ARC compatible
. [FIX] CCLabelBMFont: full unicode support
. [FIX] CCTMXXMLParser: removed unused variables in release mode
. [FIX] ColorLayer: incorrect size in init method
View
2  cocos2d/Support/CCArray.m
@@ -291,7 +291,7 @@ - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state object
- (void) insertionSortUsingCFuncComparator:(int(*)(const void *, const void *))comparator
{
-
+ insertionSort(data, comparator);
}
#pragma mark CCArray qsortUsingCFuncComparator
View
79 cocos2d/Support/ccCArray.h
@@ -45,7 +45,6 @@
#import "../ccMacros.h"
-
#pragma mark -
#pragma mark ccArray for Objects
@@ -468,60 +467,58 @@ static inline void ccCArrayFullRemoveArray(ccCArray *arr, ccCArray *minusArr)
}
//used by mergesortL
-static inline void memswp(void* a, void* b, size_t width)
-{
- if (width == sizeof(void*)) {
- // Optimization for pointer sized swap:
- void* tmp;
- tmp = *(void**)a;
- *(void**)a = *(void**)b;
- *(void**)b = tmp;
- return;
- }
- // default uses memcpy:
- char tmp[width];
- memcpy(tmp, a, width);
- memcpy(a, b, width);
- memcpy(b, tmp, width);
+static inline void pointerswap(void* a, void* b, size_t width)
+{
+ void* tmp;
+ tmp = *(void**)a;
+ *(void**)a = *(void**)b;
+ *(void**)b = tmp;
}
-
// iterative mergesort arrd on
// http://www.inf.fh-flensburg.de/lang/algorithmen/sortieren/merge/mergiter.htm
-
static inline int mergesortL(ccCArray* array, size_t width, int (*compar)(const void *, const void *))
{
- NSInteger h, i, j, k, l, m, n = array->num;
CCARRAY_ID *arr = array->arr;
- CCARRAY_ID *A; // points to an element
- //id B = NSZoneMalloc(NULL,(n/2 + 1) * width); // points to a temp array
- CCARRAY_ID *B = (CCARRAY_ID*) malloc(n * width);
+ NSInteger i,j,k,s,m,n= array->num;
- for (h = 1; h < n; h += h) {
- for (m = n - 1 - h; m >= 0; m -= h + h) {
- l = m - h + 1;
- if (l < 0)
- l = 0;
+ CCARRAY_ID *B = (CCARRAY_ID*) malloc((n/2 + 1) * width);
+ for (s = 1; s < n; s += s)
+ {
+ for (m = n-1-s; m >= 0; m -= s+s)
+ {
+ NSInteger lo = MAX(m-(s+1),0);
+ NSInteger hi = m+s;
+
+ j = lo;
+
+ if (m-j > 0)
+ {
+ memcpy(B, &arr[j], (m-j) * width);
+ }
- // Copy first half of the array into helper B:
- j = m+1;
- memcpy(B, arr + (l * width), (j-l) * width);
+ i = 0;
+ j = m;
+ k = lo;
- for (i = 0, k = l; k < j && j <= m + h; k++) {
- A = arr + (width * j); // A = [self objectAtIndex:j];
- if (compar(A, B + (i * width)) > 0) {
- memswp(arr+(k*width), B+(i*width), width); i+=1;
- } else {
- memswp(arr+(k*width), A, width); j+=1;
+ while (k<j && j <= hi)
+ {
+ if (compar(&B[i],&arr[j]) <= 0)
+ {
+ pointerswap(&arr[k++],&B[i++], width);
+ }
+
+ else
+ {
+ pointerswap(&arr[k++],&arr[j++], width);
}
}
- while (k < j) // This loop could be optimized
- memswp(arr+(k++*width), B+(i++*width), width);
+ while (k<j)
+ pointerswap(&arr[k++],&B[i++],width);
}
- }
-
- free(B);
+ }
+ free(B);
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.