perf: replace O(n²) hex-encoding loops with std::to_chars - #230
Conversation
perf: replace O(n²) hex-encoding loops with std::to_chars
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThis PR replaces O(n²) hex-encoding loops in two hot signing paths ( ChangesHex encoding optimization
🎯 2 (Simple) | ⏱️ ~10 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Infer (1.2.0)src/signer.ccsrc/signer.cc:18:10: fatal error: 'miniocpp/signer.h' file not found ... [truncated 1045 characters] ... plugins/clang/install/lib/clang/18/include" Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/signer.cc`:
- Around line 93-97: The loop converting HMAC bytes to hex uses
std::to_chars(..., hash[i], 16) which can treat char as signed and produce
negative values; fix by casting each byte to an unsigned type before conversion
(e.g., convert hash[i] to unsigned char or uint8_t and then to an integer type)
so std::to_chars sees 0..255 values. Update the call site around std::to_chars
and the hash[i] argument in signer.cc (the to_chars invocation and the
surrounding byte-to-hex logic) to use the unsigned-cast value, leaving the rest
of the hex-padding logic unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 02f84aef-c08c-41ea-b889-6d901a8a5b20
📒 Files selected for processing (2)
src/signer.ccsrc/utils.cc
perf: replace O(n²) hex-encoding loops with std::to_chars
fix #219
Summary by CodeRabbit