chore: limit Vec preallocation to follow serde convention#6616
chore: limit Vec preallocation to follow serde convention#6616LesnyRumcajs merged 1 commit intomainfrom
Vec preallocation to follow serde convention#6616Conversation
|
No actionable comments were generated in the recent review. 🎉 WalkthroughAdds a private helper Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/utils/encoding/mod.rs`:
- Around line 12-18: The helper size_hint_cautious<T> can divide by zero for
zero-sized types (ZSTs); update it to first check std::mem::size_of::<T>() and
if it is 0 return size_hint unchanged (or otherwise avoid dividing) before
computing MAX_PREALLOC_BYTES / size; modify the body of size_hint_cautious to
guard on the size (using a local let size = std::mem::size_of::<T>() and an
early return when size == 0) and then compute size_hint.min(MAX_PREALLOC_BYTES /
size).
🧹 Nitpick comments (1)
src/utils/encoding/mod.rs (1)
270-279: Add a ZST case to cover the new guard.After guarding
size_of::<T>() == 0, add a()test case so regressions are caught.🧪 Suggested test tweak
fn size_hint_cautious_test() { assert_eq!(size_hint_cautious::<u8>(0), 0); assert_eq!(size_hint_cautious::<u8>(1024 * 1024), 1024 * 1024); assert_eq!(size_hint_cautious::<u8>(2 * 1024 * 1024), 1024 * 1024); assert_eq!( size_hint_cautious::<u64>(2 * 1024 * 1024), (1024 * 1024) / std::mem::size_of::<u64>() ); + assert_eq!(size_hint_cautious::<()>(2 * 1024 * 1024), 1024 * 1024); }
|
@LesnyRumcajs CI is failing |
2fda973 to
fa6df15
Compare
fa6df15 to
99c495a
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files
... and 12 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Summary of changes
Changes introduced in this pull request:
Vecpreallocation to follow serde conventionReference issue to close (if applicable)
Closes
Other information and links
Change checklist
Outside contributions
Summary by CodeRabbit
Bug Fixes
Tests
Performance