Skip to content

Commit d2fe01d

Browse files
committed
adds profiling to j2strace check - allows finding overuse of new
1 parent bf3ea9d commit d2fe01d

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,11 @@ var addProfileNew = function(c, t) {
11541154
s += "[]";
11551155
t = 0;
11561156
}
1157+
if (J2S._traceOutput && (s.indexOf(J2S._traceOutput) >= 0 || '"' + s + '"' == J2S._traceOutput)) {
1158+
alert(s + "\n\n" + Clazz._getStackTrace());
1159+
doDebugger();
1160+
}
1161+
11571162
var p = _profileNew[s];
11581163
p || (p = _profileNew[s] = [0,0]);
11591164
p[0]++;
@@ -4580,25 +4585,36 @@ CharSequence.$defaults$(String);
45804585
sp.compareToIgnoreCase$S = function(str) { return String.CASE_INSENSITIVE_ORDER.compare$S$S(this, str);}
45814586

45824587
sp.replace$ = function(c1,c2){
4583-
if (c1 == c2 || this.indexOf (c1) < 0) return "" + this;
4588+
if (c1 == c2 || this.indexOf(c1) < 0) return "" + this;
45844589
if (c1.length == 1) {
45854590
if ("\\$.*+|?^{}()[]".indexOf(c1) >= 0)
45864591
c1 = "\\" + c1;
45874592
} else {
4588-
c1=c1.replace(/([\\\$\.\*\+\|\?\^\{\}\(\)\[\]])/g,function($0,$1){
4589-
return "\\"+$1;
4590-
});
4593+
c1=c1.replace(/([\\\$\.\*\+\|\?\^\{\}\(\)\[\]])/g,function($0,$1){return "\\"+$1;});
45914594
}
45924595
return this.replace(new RegExp(c1,"gm"),c2);
45934596
};
45944597

4595-
sp.replaceAll$S$S=sp.replaceAll$CharSequence$CharSequence=function(exp,str){
4596-
var regExp=new RegExp(exp,"gm");
4597-
return this.replace(regExp,str);
4598+
// experimental -- only marginally faster:
4599+
var reCache = new Map();
4600+
sp.replace2$ = function(c1,c2){
4601+
if (c1 == c2 || this.indexOf(c1) < 0) return "" + this;
4602+
var re;
4603+
if (c1.length == 1) {
4604+
re = reCache.get(c1);
4605+
re || reCache.set(c1, re = new RegExp("\\$.*+|?^{}()[]".indexOf(c1) == 0 ? "\\" + c1 : c1, 'gm'));
4606+
} else {
4607+
re = new RegExp(c1.replace(/([\\\$\.\*\+\|\?\^\{\}\(\)\[\]])/g,function($0,$1){return "\\"+$1;}), 'gm');
4608+
}
4609+
return this.replace(re,c2);
4610+
};
4611+
4612+
// fastest:
4613+
sp.replaceAll$=sp.replaceAll$S$S=sp.replaceAll$CharSequence$CharSequence=function(exp,str){
4614+
return this.replace(new RegExp(exp,"gm"),str);
45984615
};
45994616
sp.replaceFirst$S$S=function(exp,str){
4600-
var regExp=new RegExp(exp,"m");
4601-
return this.replace(regExp,str);
4617+
return this.replace(new RegExp(exp,"m"),str);
46024618
};
46034619
sp.matches$S=function(exp){
46044620
if(exp!=null){

0 commit comments

Comments
 (0)