Commit e932cf3
committed
perf(crc32b): optimize CRC32B implementation for better performance
## Optimizations
1. **Simplified u64 to u32 conversion**
- Removed explicit masking (result & 0xffffffff)
- Use implicit truncation: (result as u32)
- Compiler optimizes this better
2. **Eliminated redundant finalize() calls**
- result_str() now calls finalize() once instead of twice
- Directly converts result to bytes without intermediate array
3. **Reduced memory operations**
- Fewer intermediate variables
- Direct byte conversion from u32
## Performance Impact
- Reduced instruction count in hot path
- Better compiler optimization opportunities
- Maintains correctness (ISO 3309 polynomial)
## Verification
✓ Correctness: echo -n 'Test' | cksum -a crc32b → 2018365746 4
✓ Raw output: echo -n 'Test' | cksum -a crc32b --raw → 0x784DD132
✓ All tests passing
✓ Build successful1 parent 2bdadc0 commit e932cf3
1 file changed
+4
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
| 202 | + | |
| 203 | + | |
207 | 204 | | |
208 | 205 | | |
209 | 206 | | |
| |||
215 | 212 | | |
216 | 213 | | |
217 | 214 | | |
218 | | - | |
219 | | - | |
220 | | - | |
| 215 | + | |
| 216 | + | |
221 | 217 | | |
222 | 218 | | |
223 | 219 | | |
| |||
0 commit comments