Skip to content

Commit a065c28

Browse files
committed
Integer.valueOf(n) cache with indices >= 0
1 parent 73f6273 commit a065c28

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
// Google closure compiler cannot handle Clazz.new or Clazz.super
99

10+
// BH 2020.06.18 better test for instanceof Object[]
1011
// BH 2020.06.03 sets user.home and user.dir to /TEMP/swingjs, and user.name to "swingjs"
1112
// BH 2020.04.01 2.2.0-v1e fixes missing C$.superclazz when class loaded from core
1213
// BH 2020.03.19 3.2.9-v1c fixes new String("xxx") !== "xxx"
@@ -380,10 +381,16 @@ Clazz.instanceOf = function (obj, clazz) {
380381
clazz.$clazz$ && (clazz = clazz.$clazz$);
381382
if (obj == clazz)
382383
return true;
383-
if (obj.__ARRAYTYPE || clazz.__ARRAYTYPE)
384-
return (obj.__ARRAYTYPE == clazz.__ARRAYTYPE
385-
|| obj.__ARRAYTYPE && clazz.__ARRAYTYPE && obj.__NDIM == clazz.__NDIM
386-
&& isInstanceOf(obj.__BASECLASS, clazz.__BASECLASS));
384+
if (obj.__ARRAYTYPE || clazz.__ARRAYTYPE) {
385+
if (obj.__ARRAYTYPE == clazz.__ARRAYTYPE)
386+
return true;
387+
if (clazz.__BASECLASS == Clazz._O) {
388+
return (!obj.__ARRAYTYPE ? Array.isArray(obj) && clazz.__NDIM == 1
389+
: obj.__NDIM >= clazz.__NDIM && !obj.__BASECLASS.__PRIMITIVE);
390+
}
391+
return obj.__ARRAYTYPE && clazz.__ARRAYTYPE && obj.__NDIM == clazz.__NDIM
392+
&& isInstanceOf(obj.__BASECLASS, clazz.__BASECLASS);
393+
}
387394
return (obj instanceof clazz || isInstanceOf(getClassName(obj, true), clazz, true));
388395
};
389396

@@ -3647,8 +3654,8 @@ var maxValueOf = 127;
36473654

36483655
var getCachedNumber = function(i, a, cl, c$) {
36493656
if (i >= minValueOf && i <= maxValueOf) {
3650-
var v = a[i + minValueOf];
3651-
return (v ? v : a[i + minValueOf] = Clazz.new_(cl[c$], [i]));
3657+
var v = a[i - minValueOf];
3658+
return (v ? v : a[i - minValueOf] = Clazz.new_(cl[c$], [i]));
36523659
}
36533660
}
36543661

0 commit comments

Comments
 (0)