Skip to content
Permalink
Browse files
8264428: Cleanup usages of StringBuffer in java.desktop
Reviewed-by: azvegint, aivanov
  • Loading branch information
turbanoff authored and Alexander Zvegintsev committed Apr 8, 2021
1 parent 308f679 commit 8a2358074fcb12b330698bdf7d08cd2502479c07
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 45 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, 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
@@ -231,7 +231,7 @@ void dispatchComposedText(String chgText,

// Replace control character with a square box
if (chgText != null) {
StringBuffer newChgText = new StringBuffer();
StringBuilder newChgText = new StringBuilder();
for (int i=0; i < chgText.length(); i++){
char c = chgText.charAt(i);
if (Character.isISOControl(c)){
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, 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
@@ -122,9 +122,9 @@ private synchronized void initialize() {
child = new IIOMetadataNode("TIFFUndefined");

byte[] data = field.getAsBytes();
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < count; i++) {
sb.append(Integer.toString(data[i] & 0xff));
sb.append(data[i] & 0xff);
if (i < count - 1) {
sb.append(",");
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2021, 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
@@ -327,7 +327,7 @@ private String repeat(String s, int times) {
if (times == 1) {
return s;
}
StringBuffer sb = new StringBuffer((s.length() + 1)*times - 1);
StringBuilder sb = new StringBuilder((s.length() + 1)*times - 1);
sb.append(s);
for (int i = 1; i < times; i++) {
sb.append(" ");
@@ -422,12 +422,12 @@ public IIOMetadataNode getStandardDataNode() {
bitsPerSample = new int[] {1};
}
}
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < bitsPerSample.length; i++) {
if (i > 0) {
sb.append(" ");
}
sb.append(Integer.toString(bitsPerSample[i]));
sb.append(bitsPerSample[i]);
}
node = new IIOMetadataNode("BitsPerSample");
if(isPaletteColor) {
@@ -441,7 +441,7 @@ public IIOMetadataNode getStandardDataNode() {
f = getTIFFField(BaselineTIFFTagSet.TAG_FILL_ORDER);
int fillOrder = f != null ?
f.getAsInt(0) : BaselineTIFFTagSet.FILL_ORDER_LEFT_TO_RIGHT;
sb = new StringBuffer();
sb = new StringBuilder();
for (int i = 0; i < bitsPerSample.length; i++) {
if (i > 0) {
sb.append(" ");
@@ -451,7 +451,7 @@ public IIOMetadataNode getStandardDataNode() {
int msb =
fillOrder == BaselineTIFFTagSet.FILL_ORDER_LEFT_TO_RIGHT ?
maxBitIndex : 0;
sb.append(Integer.toString(msb));
sb.append(msb);
}
node = new IIOMetadataNode("SampleMSB");
if(isPaletteColor) {
@@ -1225,7 +1225,7 @@ private void mergeStandardTree(Node root)
String minute = getAttribute(child, "minute");
String second = getAttribute(child, "second");

StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
sb.append(year);
sb.append(":");
if(month.length() == 1) {
@@ -2414,13 +2414,13 @@ protected void handleReaderImport(Reader in, JTextComponent c, boolean useRead)
int nch;
boolean lastWasCR = false;
int last;
StringBuffer sbuff = null;
StringBuilder sbuff = null;

// Read in a block at a time, mapping \r\n to \n, as well as single
// \r to \n.
while ((nch = in.read(buff, 0, buff.length)) != -1) {
if (sbuff == null) {
sbuff = new StringBuffer(nch);
sbuff = new StringBuilder(nch);
}
last = 0;
for(int counter = 0; counter < nch; counter++) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, 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
@@ -155,7 +155,7 @@ public void addAll(XAtomList atoms) {
}

public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append("[");
Iterator<XAtom> iter = atoms.iterator();
while (iter.hasNext()) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, 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
@@ -81,11 +81,14 @@ public XCreateWindowParams delete(Object key) {
return this;
}
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
Iterator<Map.Entry<Object, Object>> eIter = entrySet().iterator();
while (eIter.hasNext()) {
Map.Entry<Object, Object> entry = eIter.next();
buf.append(entry.getKey() + ": " + entry.getValue() + "\n");
buf.append(entry.getKey())
.append(": ")
.append(entry.getValue())
.append("\n");
}
return buf.toString();
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 2021, 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
@@ -610,7 +610,7 @@ static int getDataModel() {
}

static String hintsToString(long flags) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
if ((flags & XUtilConstants.PMaxSize) != 0) {
buf.append("PMaxSize ");
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, 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
@@ -481,11 +481,9 @@ private String specificFontIDForName(String name) {
return name; // what else can we do?
}

StringBuffer sb =
new StringBuffer(name.substring(hPos[FAMILY_NAME_FIELD-1],
hPos[SETWIDTH_NAME_FIELD]));
sb.append(name.substring(hPos[CHARSET_REGISTRY_FIELD-1]));
String retval = sb.toString().toLowerCase (Locale.ENGLISH);
String sb = name.substring(hPos[FAMILY_NAME_FIELD-1], hPos[SETWIDTH_NAME_FIELD])
+ name.substring(hPos[CHARSET_REGISTRY_FIELD-1]);
String retval = sb.toLowerCase(Locale.ENGLISH);
return retval;
}

@@ -529,15 +527,12 @@ private String switchFontIDForName(String name) {
&& encoding.equals("fontspecific")){
registry = "adobe";
}
StringBuffer sb =
new StringBuffer(name.substring(hPos[FAMILY_NAME_FIELD-1],
hPos[SLANT_FIELD-1]+1));
sb.append(slant);
sb.append(name.substring(hPos[SLANT_FIELD],
hPos[SETWIDTH_NAME_FIELD]+1));
sb.append(registry);
sb.append(name.substring(hPos[CHARSET_ENCODING_FIELD-1]));
String retval = sb.toString().toLowerCase (Locale.ENGLISH);
String sb = name.substring(hPos[FAMILY_NAME_FIELD-1], hPos[SLANT_FIELD-1]+1)
+ slant
+ name.substring(hPos[SLANT_FIELD], hPos[SETWIDTH_NAME_FIELD]+1)
+ registry
+ name.substring(hPos[CHARSET_ENCODING_FIELD-1]);
String retval = sb.toLowerCase(Locale.ENGLISH);
return retval;
}

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, 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
@@ -787,7 +787,7 @@ int getOffset() {
}

public String toString() {
StringBuffer s = new StringBuffer();
StringBuilder s = new StringBuilder();
for (int i = 0; i < size;) {
s.append(intArray[i++]);
if (i < size)
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2021, 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
@@ -575,10 +575,7 @@ private static String toPaddedString(int n, int width) {
if (n >= 0 && len < width) {
char[] array = new char[width - len];
Arrays.fill(array, '0');
StringBuffer buffer = new StringBuffer(width);
buffer.append(array);
buffer.append(string);
string = buffer.toString();
string = String.valueOf(array) + string;
}
return string;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2021, 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
@@ -136,7 +136,7 @@ static class D3DContextCaps extends ContextCapabilities {

@Override
public String toString() {
StringBuffer buf = new StringBuffer(super.toString());
StringBuilder buf = new StringBuilder(super.toString());
if ((caps & CAPS_LCD_SHADER) != 0) {
buf.append("CAPS_LCD_SHADER|");
}

1 comment on commit 8a23580

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 8a23580 Apr 8, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.