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 { ...@@ -279,7 +279,7 @@ public class ScriptMetaData extends ScriptEntry {
if ( sourceUrl != null ) if ( sourceUrl != null )
{ {
StringBuffer buf = new StringBuffer(); StringBuilder buf = new StringBuilder();
InputStream in = sourceUrl.openStream(); InputStream in = sourceUrl.openStream();
byte[] contents = new byte[1024]; byte[] contents = new byte[1024];
......
...@@ -60,7 +60,8 @@ public class PathUtils { ...@@ -60,7 +60,8 @@ public class PathUtils {
} }
static public String make_url( String baseUrl, String url ) 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, "/"); StringTokenizer t = new StringTokenizer( url, "/");
while ( t.hasMoreElements() ) while ( t.hasMoreElements() )
{ {
......
...@@ -71,7 +71,7 @@ public class ScriptEditorForBeanShell ...@@ -71,7 +71,7 @@ public class ScriptEditorForBeanShell
ScriptEditorForBeanShell.class.getResource("template.bsh"); ScriptEditorForBeanShell.class.getResource("template.bsh");
InputStream in = url.openStream(); InputStream in = url.openStream();
StringBuffer buf = new StringBuffer(); StringBuilder buf = new StringBuilder();
byte[] b = new byte[1024]; byte[] b = new byte[1024];
int len; int len;
while ((len = in.read(b)) != -1) { while ((len = in.read(b)) != -1) {
......
...@@ -35,7 +35,7 @@ public class ScriptSourceModel { ...@@ -35,7 +35,7 @@ public class ScriptSourceModel {
} }
private String load() throws IOException { private String load() throws IOException {
StringBuffer buf = new StringBuffer(); StringBuilder buf = new StringBuilder();
InputStream in = file.openStream(); InputStream in = file.openStream();
byte[] contents = new byte[1024]; byte[] contents = new byte[1024];
......
...@@ -165,7 +165,7 @@ public class ScriptDescriptor ...@@ -165,7 +165,7 @@ public class ScriptDescriptor
@Override @Override
public String toString() public String toString()
{ {
StringBuffer description = new StringBuffer( m_name ); StringBuilder description = new StringBuilder( m_name );
Class<?>[] types = getArgumentTypes(); Class<?>[] types = getArgumentTypes();
description.append( " (" ); description.append( " (" );
......
...@@ -59,7 +59,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor ...@@ -59,7 +59,7 @@ public class ScriptEditorForJavaScript implements ScriptEditor
ScriptEditorForJavaScript.class.getResource("template.js"); ScriptEditorForJavaScript.class.getResource("template.js");
InputStream in = url.openStream(); InputStream in = url.openStream();
StringBuffer buf = new StringBuffer(); StringBuilder buf = new StringBuilder();
byte[] b = new byte[1024]; byte[] b = new byte[1024];
int len; int len;
while ((len = in.read(b)) != -1) { while ((len = in.read(b)) != -1) {
......
...@@ -160,7 +160,7 @@ public class SVersionRCFile { ...@@ -160,7 +160,7 @@ public class SVersionRCFile {
if (System.getProperty("os.name").startsWith("Windows")) if (System.getProperty("os.name").startsWith("Windows"))
path = path.replace(File.separatorChar, '/'); path = path.replace(File.separatorChar, '/');
StringBuffer buf = new StringBuffer(FILE_URL_PREFIX); StringBuilder buf = new StringBuilder(FILE_URL_PREFIX);
buf.append(path); buf.append(path);
if (f.isDirectory()) if (f.isDirectory())
......
...@@ -42,10 +42,6 @@ public class ExceptParcelFilter implements FileFilter { ...@@ -42,10 +42,6 @@ public class ExceptParcelFilter implements FileFilter {
@Override @Override
public String toString() { public String toString() {
StringBuffer buf = new StringBuffer(DESCRIPTION + ": "); return DESCRIPTION + ": " + "<" + ExceptParcelFilter.parcelName + ">";
buf.append("<" + ExceptParcelFilter.parcelName + ">");
return buf.toString();
} }
} }
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