⚡ Bolt: [performance improvement] Refactor pattern module manual argument extraction - #502
⚡ Bolt: [performance improvement] Refactor pattern module manual argument extraction#502logbie wants to merge 1 commit into
Conversation
…ment extraction 💡 What: Replaced manual `match` blocks for extracting text and pattern arguments in `src/stdlib/pattern.rs` with the `expect_text` and newly added `expect_pattern` helpers from `src/stdlib/helpers.rs`. Updated the corresponding tests in `src/stdlib/pattern_test.rs` to assert the standardized error messages produced by these helpers. 🎯 Why: To eliminate duplicated argument validation and extraction logic, adhering to the DRY principle. This streamlines the codebase, improves maintainability, and prevents redundant memory allocations and cloning. Using the central `expect_*` macros allows consistent error formatting and simplifies the native function definitions in the pattern standard library. 📊 Impact: Improved code maintainability and eliminated redundant `match` blocks. The argument validation logic is now unified across pattern functions, promoting reusability and reducing the size of individual functions. 🔬 Measurement: Executed `cargo test` to verify that the pattern module tests still pass and correctly assert the new standardized error messages (e.g., 'Expected text'). Executed `cargo clippy` and `cargo fmt` to verify code quality. Co-authored-by: logbie <1138960+logbie@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR introduces a new ChangesPattern Helper Consolidation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR refactors the stdlib pattern module to remove duplicated manual Value matching/validation and replace it with shared helpers, standardizing argument/type error behavior across the module.
Changes:
- Migrated
pattern_*native functions insrc/stdlib/pattern.rsto usecheck_arg_count,expect_text, and the newexpect_pattern. - Added
expect_patterntosrc/stdlib/helpers.rsvia the existinggenerate_expect!helper pattern. - Updated
src/stdlib/pattern_test.rsassertions to match the standardized error message wording.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/stdlib/pattern.rs |
Replaces manual argument/type extraction with shared stdlib helpers for consistency and reduced duplication. |
src/stdlib/helpers.rs |
Adds expect_pattern extractor to support consolidated pattern argument validation. |
src/stdlib/pattern_test.rs |
Aligns tests with the standardized “expects N arguments” / “Expected text” error messaging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary of Changes
src/stdlib/pattern.rsfile had manual duplicate logic to pattern-match and validateValueenums (e.g.Value::TextandValue::Pattern). This was highly verbose and inefficient for checking argument types and returning customRuntimeErrors.expect_*andcheck_arg_counthelpers improves maintainability by adhering to the DRY principle, reduces redundant error instantiation, and makes the module much more concise, directly resolving technical debt.expect_patternmacro tosrc/stdlib/helpers.rsand migrated thepattern.rsfunctions (pattern_matches_native,pattern_find_native,pattern_find_all_native,native_pattern_replace,native_pattern_split) to use the consolidated extraction logic. Refactored the unit tests insrc/stdlib/pattern_test.rsto check for the standardized error messageExpected textandexpects 2 arguments.Verification Checklist
cargo fmtexecuted and passed.cargo clippyreturned no warnings or errors.cargo testsuites passed (100% success rate).PR created automatically by Jules for task 3879846073613580161 started by @logbie
Summary by CodeRabbit
Refactor
Bug Fixes