Skip to content

Commit

Permalink
Use popcount instead of manually counting bits
Browse files Browse the repository at this point in the history
This should work on Windows too as popcount is one of those intrinsics available on there as well.
  • Loading branch information
AZero13 committed Nov 1, 2023
1 parent 8a9b69b commit 2d71bb9
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions CoreFoundation/URL.subproj/CFURL.c
Original file line number Diff line number Diff line change
Expand Up @@ -2381,13 +2381,7 @@ CFURLRef _CFURLCopyFileURL(CFURLRef url)
// get just the component flag bits
UInt32 flags = url->_flags & ALL_COMPONENTS_MASK;
// get the rangeCount -- the number of component flag bits set
CFIndex rangeCount = 0;
while ( flags != 0 ) {
if ( flags & 1 ) {
++rangeCount;
}
flags >>= 1;
}
CFIndex rangeCount = __builtin_popcount(flags);
result = _CFURLAlloc(allocator, rangeCount);
if ( result ) {
// copy the URL fields from _flags to _ranges
Expand Down

0 comments on commit 2d71bb9

Please sign in to comment.