For concatenation of 2 strings that are not null use str1.concat(str2) instead of str1+str2 to avoid construction of temporary StringBuffer all together.

This commit is contained in:
igor%mir2.org 2003-03-19 12:36:48 +00:00
Родитель ec1028b7f8
Коммит cdf7a42c64
3 изменённых файлов: 16 добавлений и 9 удалений

Просмотреть файл

@ -2633,9 +2633,14 @@ public class Interpreter {
lhs = ((Scriptable) lhs).getDefaultValue(null);
if (rhs instanceof Scriptable)
rhs = ((Scriptable) rhs).getDefaultValue(null);
if (lhs instanceof String || rhs instanceof String) {
stack[stackTop] = ScriptRuntime.toString(lhs)
+ ScriptRuntime.toString(rhs);
if (lhs instanceof String) {
String lstr = (String)lhs;
String rstr = ScriptRuntime.toString(rhs);
stack[stackTop] = lstr.concat(rstr);
} else if (rhs instanceof String) {
String lstr = ScriptRuntime.toString(lhs);
String rstr = (String)rhs;
stack[stackTop] = lstr.concat(rstr);
} else {
double lDbl = (lhs instanceof Number)
? ((Number)lhs).doubleValue() : ScriptRuntime.toNumber(lhs);
@ -2647,7 +2652,7 @@ public class Interpreter {
}
}
// x + y when x is Number, see
// x + y when x is Number
private static void do_add
(Object lhs, double rDbl,
Object[] stack, double[] stackDbl, int stackTop,
@ -2661,10 +2666,12 @@ public class Interpreter {
}
}
if (lhs instanceof String) {
String lstr = (String)lhs;
String rstr = ScriptRuntime.toString(rDbl);
if (left_right_order) {
stack[stackTop] = (String)lhs + ScriptRuntime.toString(rDbl);
stack[stackTop] = lstr.concat(rstr);
} else {
stack[stackTop] = ScriptRuntime.toString(rDbl) + (String)lhs;
stack[stackTop] = rstr.concat(lstr);
}
} else {
double lDbl = (lhs instanceof Number)

Просмотреть файл

@ -1340,7 +1340,7 @@ public class ScriptRuntime {
((Number)val2).doubleValue());
else
return new Double(toNumber(val1) + toNumber(val2));
return toString(val1) + toString(val2);
return toString(val1).concat(toString(val2));
}
public static Object postIncrement(Object value) {

Просмотреть файл

@ -109,7 +109,7 @@ public final class OptRuntime extends ScriptRuntime {
val1 = ((Scriptable) val1).getDefaultValue(null);
if (!(val1 instanceof String))
return new Double(toNumber(val1) + val2);
return toString(val1) + toString(val2);
return toString(val1).concat(toString(val2));
}
public static Object add(double val1, Object val2) {
@ -117,7 +117,7 @@ public final class OptRuntime extends ScriptRuntime {
val2 = ((Scriptable) val2).getDefaultValue(null);
if (!(val2 instanceof String))
return new Double(toNumber(val2) + val1);
return toString(val1) + toString(val2);
return toString(val1).concat(toString(val2));
}
public static boolean neq(Object x, Object y) {