Skip to content

Commit 8b9f6a7

Browse files
Adding code formatting.
1 parent 03ce6f9 commit 8b9f6a7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cppcon2025/cppcon_2025_slides.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,15 +1069,18 @@ How Fast Digit Counting Works
10691069
The Problem: Need to know buffer size before converting number to string
10701070

10711071
Traditional Approach:
1072+
```cpp
10721073
size_t digit_count(uint64_t v) {
10731074
return std::to_string(v).length();
10741075
// 1. Allocates memory
10751076
// 2. Converts entire number to string
10761077
// 3. Gets length
10771078
// 4. Deallocates string
10781079
}
1080+
```
10791081
10801082
Our Optimization:
1083+
```cpp
10811084
int fast_digit_count(uint64_t x) {
10821085
// Approximate using bit operations (no division!)
10831086
int y = (19 * int_log2(x) >> 6);
@@ -1088,6 +1091,7 @@ int fast_digit_count(uint64_t x) {
10881091
10891092
return y + 1;
10901093
}
1094+
```
10911095

10921096
Zero allocations, no string conversion, just math!
10931097

0 commit comments

Comments
 (0)