⚡ Bolt: Replace regex-based replaceFirst with indexOf/substring#291
Conversation
**What:** Replaced `String.replaceFirst()` with `startsWith()` and `indexOf()` combined with `substring()` in `FilterMethodVisitor.java`, `TestMethodDivinerJunit3Praefix.java`, and `TestMethodDivinerNoPraefix.java`. **Why:** `String.replaceFirst()` implicitly compiles a regex `Pattern` and invokes the matcher logic, which is slow for simple literal substring removal. Given that `FilterMethodVisitor` frequently parses AST structures and processes string names, this regex overhead was unnecessary. Literal substring removal is far faster. **Impact:** Improves execution performance within plugin string parsers and resolves potential bugs where literal regex characters (e.g. `$`) might cause exceptions. **Measurement:** Run `xvfb-run -a mvn -f org.moreunit.build/pom.xml test` to verify changes build successfully. Co-authored-by: RoiSoleil <3462260+RoiSoleil@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. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #291 +/- ##
============================================
+ Coverage 75.58% 75.67% +0.09%
- Complexity 3362 3378 +16
============================================
Files 427 428 +1
Lines 14759 14827 +68
Branches 1279 1288 +9
============================================
+ Hits 11155 11221 +66
- Misses 3067 3068 +1
- Partials 537 538 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
**What:** Added unit tests covering the `index == -1` (no match) edge cases in `TestMethodDivinerNoPraefixTest` and `TestMethodDivinerJunit3PraefixTest`. **Why:** The previous refactoring from `replaceFirst` to `indexOf` introduced a new `if (index != -1)` branch which was not covered by existing tests, causing the Codecov CI check to fail due to a drop in diff coverage. **Impact:** Increases code coverage and ensures that renaming methods correctly fallback when the expected prefix/suffix string does not exist in the target string. Co-authored-by: RoiSoleil <3462260+RoiSoleil@users.noreply.github.com>
💡 What:
Replaced regex-based
String.replaceFirst()with direct substring operations (startsWith,indexOf, andsubstring) in the following files:FilterMethodVisitor.javaTestMethodDivinerJunit3Praefix.javaTestMethodDivinerNoPraefix.java🎯 Why:
String.replaceFirst()compiles a regular expression under the hood, which creates significant execution overhead for simple prefix/suffix and literal replacements. SinceFilterMethodVisitorfrequently processes AST structures, this optimization speeds up method filtering and renaming operations. Additionally, it eliminates edge cases where literal string contents could be mistakenly parsed as regex capture groups or metacharacters.📊 Impact:
Eliminates regular expression overhead, improving string manipulation speed across the AST visitors and test diviner utilities.
🔬 Measurement:
The correctness of the logic is proven by passing the test suite:
xvfb-run -a mvn -f org.moreunit.build/pom.xml test.PR created automatically by Jules for task 852307941229828869 started by @RoiSoleil