Skip to content

Commit 0c44350

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 4a9694d commit 0c44350

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

Sources/CoreFoundation/CFURL.c

+1-7
Original file line numberDiff line numberDiff line change
@@ -2375,13 +2375,7 @@ CFURLRef _CFURLCopyFileURL(CFURLRef url)
23752375
// get just the component flag bits
23762376
UInt32 flags = url->_flags & ALL_COMPONENTS_MASK;
23772377
// get the rangeCount -- the number of component flag bits set
2378-
CFIndex rangeCount = 0;
2379-
while ( flags != 0 ) {
2380-
if ( flags & 1 ) {
2381-
++rangeCount;
2382-
}
2383-
flags >>= 1;
2384-
}
2378+
CFIndex rangeCount = __builtin_popcount(flags);
23852379
result = _CFURLAlloc(allocator, rangeCount);
23862380
if ( result ) {
23872381
// copy the URL fields from _flags to _ranges

0 commit comments

Comments
 (0)