Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace StringBuffer with StringBuilder where possible #30964

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public abstract class AnalysisFactoryTestCase extends ESTestCase {

private static String toCamelCase(String s) {
Matcher m = UNDERSCORE_THEN_ANYTHING.matcher(s);
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
while (m.find()) {
m.appendReplacement(sb, m.group(1).toUpperCase());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one has the same problem with java 8.

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public Object getValue(String key) throws IOException {
* String*Buffer* because that is what the Matcher API takes. In modern versions of java the uncontended synchronization is very,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment looks obsolete

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I should read more comments to save me some trouble ;-) Nik is right here of course.

* very cheap so that should not be a problem.
*/
StringBuffer result = new StringBuffer(key.length());
StringBuilder result = new StringBuilder(key.length());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one also has the same problem with java 8.

if (false == matcher.find()) {
throw new IllegalArgumentException("Doesn't contain any stash keys [" + key + "]");
}
Expand Down Expand Up @@ -191,7 +191,7 @@ private Object getValue(List<Object> path, String key) throws IOException {
}
}
String builtPath = Matcher.quoteReplacement(pathBuilder.toString());
StringBuffer newKey = new StringBuffer(key.length());
StringBuilder newKey = new StringBuilder(key.length());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one also uses a Java 9 method.

do {
matcher.appendReplacement(newKey, builtPath);
} while (matcher.find());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static String convertToString( byte[] bytes )
}

char[] hex = Hex.encodeHex( bytes );
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we should avoid changing this source file. It is from upstream (see #30972 to fix the license) and we should not deviate unless absolutely necessary (it could get reverted in a future import from upstream anyway).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, will close this then.


// start with 'S'
sb.append( 'S' );
Expand All @@ -65,7 +65,7 @@ static String convertToString( byte[] bytes )
// sub-authorities, little-endian
for ( int i = 0; i < count; i++ )
{
StringBuffer rid = new StringBuffer();
StringBuilder rid = new StringBuilder();

for ( int k = 3; k >= 0; k-- )
{
Expand Down