Skip to content

Commit 2d71bb9

Browse files
committed
Use popcount instead of manually counting bits
This should work on Windows too as popcount is one of those intrinsics available on there as well.
1 parent 8a9b69b commit 2d71bb9

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

CoreFoundation/URL.subproj/CFURL.c

+1-7
Original file line numberDiff line numberDiff line change
@@ -2381,13 +2381,7 @@ CFURLRef _CFURLCopyFileURL(CFURLRef url)
23812381
// get just the component flag bits
23822382
UInt32 flags = url->_flags & ALL_COMPONENTS_MASK;
23832383
// get the rangeCount -- the number of component flag bits set
2384-
CFIndex rangeCount = 0;
2385-
while ( flags != 0 ) {
2386-
if ( flags & 1 ) {
2387-
++rangeCount;
2388-
}
2389-
flags >>= 1;
2390-
}
2384+
CFIndex rangeCount = __builtin_popcount(flags);
23912385
result = _CFURLAlloc(allocator, rangeCount);
23922386
if ( result ) {
23932387
// copy the URL fields from _flags to _ranges

0 commit comments

Comments
 (0)