Skip to content

Commit 64f41f1

Browse files
committed
Move the size check to be the first thing checked in CFAllocatorCreate
This saves us a lot of work is size is 0
1 parent de5f7ed commit 64f41f1

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

CoreFoundation/Base.subproj/CFBase.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,9 @@ CFAllocatorRef CFAllocatorCreate(CFAllocatorRef allocator, CFAllocatorContext *c
581581

582582
void *CFAllocatorAllocate(CFAllocatorRef allocator, CFIndex size, CFOptionFlags hint) {
583583
CFAllocatorAllocateCallBack allocateFunc;
584-
void *newptr = NULL;
584+
void *newptr;
585+
586+
if (0 == size) return NULL;
585587

586588
if (NULL == allocator) {
587589
allocator = __CFGetDefaultAllocator();
@@ -594,14 +596,13 @@ void *CFAllocatorAllocate(CFAllocatorRef allocator, CFIndex size, CFOptionFlags
594596
#else
595597
__CFGenericValidateType(allocator, _kCFRuntimeIDCFAllocator);
596598
#endif
597-
if (0 == size) return NULL;
598599
#if TARGET_OS_MAC
599600
if (_CFTypeGetClass(allocator) != __CFISAForCFAllocator()) { // malloc_zone_t *
600601
return malloc_zone_malloc((malloc_zone_t *)allocator, size);
601602
}
602603
#endif
603-
newptr = NULL;
604604
allocateFunc = __CFAllocatorGetAllocateFunction(&allocator->_context);
605+
newptr = NULL;
605606
if (allocateFunc) {
606607
newptr = (void *)INVOKE_CALLBACK3(allocateFunc, size, hint, allocator->_context.info);
607608
}

0 commit comments

Comments
 (0)