Skip to content

Commit de3d3e4

Browse files
committed
Tweak documentation
1 parent 66263c8 commit de3d3e4

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

java/ql/src/Performance/StringReplaceAllWithNonRegex.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Using `String#replaceAll` is less performant than `String#replace` when the firs
44

55
## Overview
66

7-
The underlying implementation of `String#replaceAll` uses `Pattern#compile` and expects a regular expression as its first argument. However in cases where the argument could be represented by just a plain `String` that does not represent an interesting regular expression, a call to `String#replace` may be more performant as it does not need to compile the regular expression.
7+
The `String#replaceAll` method is designed to work with regular expressions as its first parameter. When you use a simple string without any regex patterns (like special characters or syntax), it's more efficient to use `String#replace` instead. This is because `replaceAll` has to compile the input as a regular expression first, which adds unnecessary overhead when you are just replacing literal text.
88

99
## Recommendation
1010

java/ql/src/Performance/StringReplaceAllWithNonRegex.ql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* @id java/string-replace-all-with-non-regex
33
* @name Use of `String#replaceAll` with a first argument which is not a regular expression
4-
* @description Using `String#replaceAll` is less performant than `String#replace` when the first
5-
* argument is not a regular expression.
4+
* @description Using `String#replaceAll` with a first argument which is not a regular expression
5+
* is less efficient than using `String#replace`.
66
* @kind problem
77
* @precision very-high
88
* @problem.severity recommendation

0 commit comments

Comments
 (0)