Skip to content

Commit 960a424

Browse files
hansonrhansonr
authored andcommitted
SwingJS fix for Character.valueOf cache
1 parent 0c88387 commit 960a424

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3654,11 +3654,15 @@ Integer.SIZE=Integer.prototype.SIZE=32;
36543654
var ints = [];
36553655
var longs = [];
36563656
var shorts = [];
3657+
var chars = {};
36573658

36583659
var minValueOf = -128;
36593660
var maxValueOf = 127;
36603661

36613662
var getCachedNumber = function(i, a, cl, c$) {
3663+
if (a == chars) {
3664+
return a[i] ? a[i] : (a[i] = Clazz.new_(cl[c$], [i]));
3665+
}
36623666
if (i >= minValueOf && i <= maxValueOf) {
36633667
var v = a[i - minValueOf];
36643668
return (v ? v : a[i - minValueOf] = Clazz.new_(cl[c$], [i]));
@@ -5170,7 +5174,10 @@ function(codePoint){
51705174
return (pt1 < 0 ? "??" : unicode_txt.substring(pt + 6, pt1));
51715175
}, 1);
51725176

5173-
m$(C$,"valueOf$C",function(c){return Clazz.new_(Character.c$, [c]);},1);
5177+
m$(C$,"valueOf$C",function(c){
5178+
return (c <= '\u007F' ? getCachedNumber(c, chars, Character, "c$$C")
5179+
: Clazz.new_(Character.c$$C, [c]));
5180+
},1);
51745181

51755182
C$.prototype.$c = function(){return this.value.charCodeAt(0)};
51765183

0 commit comments

Comments
 (0)