Kaydet (Commit) 44304a81 authored tarafından rbuj's avatar rbuj Kaydeden (comit) Noel Grandin

scripting: replace StringBuffer with StringBuilder method

In JDK 1.3, StringBuffer makes the String concatenations faster.

public String concat(String s1, String s2) {
  StringBuffer sb = new StringBuffer();
  sb.append(s1);
  sb.append(s2);
  return sb.toString();
}

JDK 1.5 comes with StringBuilder (which is faster than StringBuffer) and the method:

public String concat(String s1, String s2) {
  return s1 + s2;
}

is translated to:

public String concat(String s1, String s2) {
  return new StringBuilder().append(s1).append(s2).toString();
}

Change-Id: I2924fcdf23d7ffbb567d9e924d02edcab4d21be6
NOTE: StringBuffer is synchronized, StringBuilder is not.
Reviewed-on: https://gerrit.libreoffice.org/11436Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
Tested-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst 40f1849e
......@@ -279,7 +279,7 @@ public class ScriptMetaData extends ScriptEntry {
if ( sourceUrl != null )
{
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
InputStream in = sourceUrl.openStream();
byte[] contents = new byte[1024];
......
......@@ -60,7 +60,8 @@ public class PathUtils {
}
static public String make_url( String baseUrl, String url )
{
StringBuffer buff = new StringBuffer( baseUrl.length() + url.length() ); buff.append( baseUrl );
StringBuilder buff = new StringBuilder( baseUrl.length() + url.length() );
buff.append( baseUrl );
StringTokenizer t = new StringTokenizer( url, "/");
while ( t.hasMoreElements() )
{
......
......@@ -71,7 +71,7 @@ public class ScriptEditorForBeanShell
ScriptEditorForBeanShell.class.getResource("template.bsh");
InputStream in = url.openStream();
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
byte[] b = new byte[1024];
int len;
while ((len = in.read(b)) != -1) {
......
......@@ -35,7 +35,7 @@ public class ScriptSourceModel {
}
private String load() throws IOException {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
InputStream in = file.openStream();
byte[] contents = new byte[1024];
......
......@@ -165,7 +165,7 @@ public class ScriptDescriptor
@Override
public String toString()
{
StringBuffer description = new StringBuffer( m_name );
StringBuilder description = new StringBuilder( m_name );
Class<?>[] types = getArgumentTypes();
description.append( " (" );
......
......@@ -59,7 +59,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor
ScriptEditorForJavaScript.class.getResource("template.js");
InputStream in = url.openStream();
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
byte[] b = new byte[1024];
int len;
while ((len = in.read(b)) != -1) {
......
......@@ -160,7 +160,7 @@ public class SVersionRCFile {
if (System.getProperty("os.name").startsWith("Windows"))
path = path.replace(File.separatorChar, '/');
StringBuffer buf = new StringBuffer(FILE_URL_PREFIX);
StringBuilder buf = new StringBuilder(FILE_URL_PREFIX);
buf.append(path);
if (f.isDirectory())
......
......@@ -42,10 +42,6 @@ public class ExceptParcelFilter implements FileFilter {
@Override
public String toString() {
StringBuffer buf = new StringBuffer(DESCRIPTION + ": ");
buf.append("<" + ExceptParcelFilter.parcelName + ">");
return buf.toString();
return DESCRIPTION + ": " + "<" + ExceptParcelFilter.parcelName + ">";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment