8294397: Replace StringBuffer with StringBuilder within java.text

Reviewed-by: lancea, naoto, bchristi
This commit is contained in:
Justin Lu 2022-10-05 18:42:00 +00:00 committed by Naoto Sato
parent f2c57186a4
commit 87acfee3c3
7 changed files with 55 additions and 80 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -776,7 +776,7 @@ public final class CollationElementIterator
private NormalizerBase text = null;
private int[] buffer = null;
private int expIndex = 0;
private StringBuffer key = new StringBuffer(5);
private StringBuilder key = new StringBuilder(5);
private int swapOrder = 0;
private RBCollationTables ordering;
private RuleBasedCollator owner;

View file

@ -161,12 +161,12 @@ final class DigitList implements Cloneable {
return 0.0;
}
StringBuffer temp = getStringBuffer();
temp.append('.');
temp.append(digits, 0, count);
temp.append('E');
temp.append(decimalAt);
return Double.parseDouble(temp.toString());
return Double.parseDouble(getStringBuilder()
.append('.')
.append(digits, 0, count)
.append('E')
.append(decimalAt)
.toString());
}
/**
@ -187,7 +187,7 @@ final class DigitList implements Cloneable {
return Long.MIN_VALUE;
}
StringBuffer temp = getStringBuffer();
StringBuilder temp = getStringBuilder();
temp.append(digits, 0, count);
for (int i = count; i < decimalAt; ++i) {
temp.append('0');
@ -736,7 +736,7 @@ final class DigitList implements Cloneable {
char[] newDigits = new char[digits.length];
System.arraycopy(digits, 0, newDigits, 0, digits.length);
other.digits = newDigits;
other.tempBuffer = null;
other.tempBuilder = null;
return other;
} catch (CloneNotSupportedException e) {
throw new InternalError(e);
@ -788,23 +788,24 @@ final class DigitList implements Cloneable {
if (isZero()) {
return "0";
}
StringBuffer buf = getStringBuffer();
buf.append("0.");
buf.append(digits, 0, count);
buf.append("x10^");
buf.append(decimalAt);
return buf.toString();
return getStringBuilder()
.append("0.")
.append(digits, 0, count)
.append("x10^")
.append(decimalAt)
.toString();
}
private StringBuffer tempBuffer;
private StringBuilder tempBuilder;
private StringBuffer getStringBuffer() {
if (tempBuffer == null) {
tempBuffer = new StringBuffer(MAX_COUNT);
private StringBuilder getStringBuilder() {
if (tempBuilder == null) {
tempBuilder = new StringBuilder(MAX_COUNT);
} else {
tempBuffer.setLength(0);
tempBuilder.setLength(0);
}
return tempBuffer;
return tempBuilder;
}
private void extendDigits(int len) {

View file

@ -101,18 +101,18 @@ final class MergeCollation {
PatternEntry last = findLastWithNoExtension(i-1);
for (int j = extList.size() - 1; j >= 0 ; j--) {
tmp = extList.get(j);
tmp.addToBuffer(result, false, withWhiteSpace, last);
tmp.addToBuilder(result, false, withWhiteSpace, last);
}
extList = null;
}
entry.addToBuffer(result, false, withWhiteSpace, null);
entry.addToBuilder(result, false, withWhiteSpace, null);
}
}
if (extList != null) {
PatternEntry last = findLastWithNoExtension(i-1);
for (int j = extList.size() - 1; j >= 0 ; j--) {
tmp = extList.get(j);
tmp.addToBuffer(result, false, withWhiteSpace, last);
tmp.addToBuilder(result, false, withWhiteSpace, last);
}
extList = null;
}
@ -151,7 +151,7 @@ final class MergeCollation {
{
PatternEntry entry = patterns.get(i);
if (entry != null) {
entry.addToBuffer(result, true, withWhiteSpace, null);
entry.addToBuilder(result, true, withWhiteSpace, null);
}
}
return result.toString();
@ -211,7 +211,7 @@ final class MergeCollation {
// This is really used as a local variable inside fixEntry, but we cache
// it here to avoid newing it up every time the method is called.
private transient StringBuffer excess = new StringBuffer();
private transient StringBuilder excess = new StringBuilder();
//
// When building a MergeCollation, we need to do lots of searches to see
@ -300,7 +300,7 @@ final class MergeCollation {
}
private final int findLastEntry(PatternEntry entry,
StringBuffer excessChars) throws ParseException
StringBuilder excessChars) throws ParseException
{
if (entry == null)
return 0;

View file

@ -84,7 +84,7 @@ class PatternEntry {
*/
public String toString() {
StringBuilder result = new StringBuilder();
addToBuffer(result, true, false, null);
addToBuilder(result, true, false, null);
return result.toString();
}
@ -111,10 +111,10 @@ class PatternEntry {
// ===== privates =====
void addToBuffer(StringBuilder toAddTo,
boolean showExtension,
boolean showWhiteSpace,
PatternEntry lastEntry)
void addToBuilder(StringBuilder toAddTo,
boolean showExtension,
boolean showWhiteSpace,
PatternEntry lastEntry)
{
if (showWhiteSpace && toAddTo.length() > 0)
if (strength == Collator.PRIMARY || lastEntry != null)
@ -190,8 +190,8 @@ class PatternEntry {
//========================================================================
PatternEntry(int strength,
StringBuffer chars,
StringBuffer extension)
StringBuilder chars,
StringBuilder extension)
{
this.strength = strength;
this.chars = chars.toString();
@ -287,8 +287,8 @@ class PatternEntry {
}
// We re-use these objects in order to improve performance
private StringBuffer newChars = new StringBuffer();
private StringBuffer newExtension = new StringBuffer();
private StringBuilder newChars = new StringBuilder();
private StringBuilder newExtension = new StringBuilder();
}