feat(allocator): add String::set_len method#10757
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
WalkthroughA new unsafe method 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (16)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/oxc_allocator/src/string.rs (1)
302-316: Method implementation looks good, but consider adding tests.The
set_lenmethod is correctly implemented, with thorough safety documentation covering all the important invariants that callers must maintain. The function correctly delegates to the underlying vector'sset_lenmethod, matching the expected behavior ofVec::set_len.Consider adding tests for this method to verify it works correctly in various scenarios, especially since it's an unsafe method with important invariants. For example, you could test:
- Setting to a smaller length (truncation)
- Setting to a equal length (no change)
- Verifying UTF-8 boundary requirements
#[test] fn test_set_len() { let allocator = Allocator::default(); // Test truncation let mut string = String::from_str_in("hello world", &allocator); unsafe { string.set_len(5) }; // Truncate to "hello" assert_eq!(string, "hello"); // Test setting to same length let original_len = string.len(); unsafe { string.set_len(original_len) }; assert_eq!(string, "hello"); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/oxc_allocator/src/string.rs(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
- GitHub Check: Benchmark (codegen)
- GitHub Check: Benchmark (formatter)
- GitHub Check: Benchmark (parser)
- GitHub Check: Benchmark (minifier)
- GitHub Check: Benchmark (transformer)
- GitHub Check: Benchmark (lexer)
- GitHub Check: Conformance
- GitHub Check: Clippy
- GitHub Check: Build Linter Benchmark
- GitHub Check: Test NAPI
- GitHub Check: Miri
CodSpeed Instrumentation Performance ReportMerging #10757 will not alter performanceComparing Summary
|
|
This was originally added for #10758, which is now closed. But it's still a useful addition to API. |
Merge activity
|
Add unsafe `String::set_len` method to match `Vec::set_len`.
1b4d9ff to
c02fcef
Compare
Add unsafe `String::set_len` method to match `Vec::set_len`.
c02fcef to
767dada
Compare
Add unsafe `String::set_len` method to match `Vec::set_len`.
05b9380 to
4b4b09e
Compare

Add unsafe
String::set_lenmethod to matchVec::set_len.