-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
performanceMust go fasterMust go faster
Description
Inspired by #2097 .
Try this code:
Lines 2496 to 2504 in 737ce4a
| // Since the bit width of 0 is 0x0, special-case it instead of complicating the math even more. | |
| int _Width = 3; | |
| if (_Value != nullptr) { | |
| // Compute the bit width of the pointer (i.e. how many bits it takes to be represented). | |
| // Add 3 to the bit width so we always round up on the division. | |
| // Divide that by the amount of bits a hexit represents (log2(16) = log2(2^4) = 4). | |
| // Add 2 for the 0x prefix. | |
| _Width = static_cast<int>(2 + (_STD bit_width(reinterpret_cast<uintptr_t>(_Value)) + 3) / 4); | |
| } |
On Godbolt's compiler explorer: https://godbolt.org/z/z99vjeEhh
Metadata
Metadata
Assignees
Labels
performanceMust go fasterMust go faster