Skip to content

Commit

Permalink
Don't wrap integers in CFBinaryHeap benchmark in NSNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
AquaGeek committed Jul 16, 2021
1 parent 8d2bf0a commit a97bca2
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions Benchmarks/CppBenchmarks/src/BinaryHeap.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@ @implementation BinaryHeap
CFBinaryHeapRef _storage;
}

static const void *HeapRetain(CFAllocatorRef allocator, const void *object)
{
return CFRetain(object);
}

static void HeapRelease(CFAllocatorRef allocator, const void *object)
{
CFRelease(object);
}

static CFComparisonResult HeapCompare(const void *lhs, const void *rhs, void *context)
{
return (CFComparisonResult)[(__bridge id)lhs compare:(__bridge id)rhs];
if (*(NSInteger *)lhs == *(NSInteger *)rhs) {
return kCFCompareEqualTo;
} else if (*(NSInteger *)lhs < *(NSInteger *)rhs) {
return kCFCompareLessThan;
} else {
return kCFCompareGreaterThan;
}
}

- (instancetype)init
Expand All @@ -39,8 +35,8 @@ - (instancetype)init
{
CFBinaryHeapCallBacks callbacks = (CFBinaryHeapCallBacks){
.version = 0,
.retain = &HeapRetain,
.release = &HeapRelease,
.retain = NULL,
.release = NULL,
.copyDescription = &CFCopyDescription,
.compare = &HeapCompare
};
Expand All @@ -62,15 +58,19 @@ - (NSUInteger)count

- (void)insert:(NSInteger)value
{
NSNumber *val = @(value);
CFBinaryHeapAddValue(_storage, (__bridge const void *)val);
NSInteger *val = malloc(sizeof(NSInteger));
*val = value;
CFBinaryHeapAddValue(_storage, val);
}

- (NSInteger)popMinimum
{
NSNumber *val = CFBinaryHeapGetMinimum(_storage);
const NSInteger *val = CFBinaryHeapGetMinimum(_storage);
CFBinaryHeapRemoveMinimumValue(_storage);
return val.integerValue;

NSInteger value = *val;
free((void *)val);
return value;
}

@end

0 comments on commit a97bca2

Please sign in to comment.