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/11436 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
This commit is contained in:
@@ -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) {
|
||||
|
Reference in New Issue
Block a user