Skip to content

Commit e6940b8

Browse files
hansonrhansonr
authored andcommitted
fixes startProfiling() and getProfile()
corrects misspelling for String.toUpperCaseLocale()
1 parent b6c8989 commit e6940b8

File tree

1 file changed

+18
-47
lines changed

1 file changed

+18
-47
lines changed

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

Lines changed: 18 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
// TODO: still a lot of references to window[...]
1111

12+
// BH 1/8/2019 3.2.4.07 fixes String.prototype.to[Upper|Lower]Case$java_util_Locale - using toLocal[Upper|Lower]Case()
1213
// BH 1/3/2019 3.2.4.07 adds ByteBuffer/CharBuffer support, proper CharSet encoding, including GBK (Standard Chinese)
1314

1415
// see earlier notes at net.sf.j2s.java.core.srcjs/js/devnotes.txt
@@ -834,82 +835,51 @@ Clazz.setConsoleDiv = function(d) {
834835
// which could be a bottle-neck for function calling.
835836
// This is critical for performance optimization.
836837

837-
var _profile = null;
838-
var _profileNoOpt = false; // setting this true will remove Bob's signature optimization
839-
840838
var __signatures = "";
841839
var profilet0;
842840
var _profileNew = null;
843841
var _jsid0 = 0;
844842

845843
Clazz.startProfiling = function(doProfile) {
844+
_profileNew = {};
846845
if (typeof doProfile == "number") {
847-
_profileNew = (arguments[1] ? {} : null);
848846
_jsid0 = _jsid;
849847
setTimeout(function() { var s = "total wall time: " + doProfile + " sec\n" + Clazz.getProfile(); console.log(s); System.out.println(s)}, doProfile * 1000);
848+
} else if (!doProfile) {
849+
_jsid = 0;
850+
_profileNew = null;
850851
}
851-
_profile = ((doProfile || arguments.length == 0) && self.JSON && window.performance ? {} : null);
852-
return (_profile ? "use Clazz.getProfile() to show results" : "profiling stopped and cleared")
852+
return (_profileNew ? "use Clazz.getProfile() to show results" : "profiling stopped and cleared")
853853
}
854854

855855
var tabN = function(n) { n = ("" + n).split(".")[0]; return "..........".substring(n.length) + n + "\t" };
856856

857857
Clazz.getProfile = function() {
858858
var s = "run Clazz.startProfiling() first";
859-
if (_profile) {
860-
var l = [];
861-
var totalcount = 0;
862-
var totalprep = 0;
863-
var totaltime = 0;
864-
for (var name in _profile) {
865-
var n = _profile[name][0];
866-
var t1 = _profile[name][1];
867-
var t2 = _profile[name][2];
868-
l.push(tabN(n) + tabN(t1) + tabN(t2) + name);
869-
totalcount += n
870-
totalprep += t1
871-
totaltime += t2
872-
}
873-
s = "\ncount \tprep(ms)\texec(ms)\n"
874-
+ "--------\t--------\t--------\n"
875-
+ tabN(totalcount)+ tabN(totalprep)+tabN(totaltime) + "\n"
876-
+ "--------\t--------\t--------\n"
877-
+ l.sort().reverse().join("\n")
878-
;
879-
_profile = null;
880859

881860
if (_profileNew) {
882861
s += "\n\n Total new objects: " + (_jsid - _jsid0) + "\n";
883862
s += "\ncount \texec(ms)\n";
884863
s += "--------\t--------\t------------------------------\n";
885864
totalcount = 0;
886865
totaltime = 0;
866+
var rows = [];
887867
for (var key in _profileNew) {
888868
var count = _profileNew[key][0];
889869
var tnano = _profileNew[key][1];
890-
totalcount += count
891-
totaltime += tnano
892-
s += tabN(count) + tabN(tnano) + "\t" +key + "\n";
870+
totalcount += count;
871+
totaltime += tnano;
872+
rows.push(tabN(count) + tabN(tnano) + "\t" +key + "\n");
893873
}
894-
s+= tabN(totalcount)+tabN(totaltime) + "\n"
874+
rows.sort();
875+
rows.reverse();
876+
s += rows.join("");
877+
s+= tabN(totalcount)+tabN(totaltime) + "\n";
895878
}
896-
}
897879
_profileNew = null;
898880
return s; //+ __signatures;
899881
}
900882

901-
902-
var addProfile = function(c, f, p, t1, t2) {
903-
var s = c.__CLASS_NAME__ + " " + f + " ";// + JSON.stringify(p);
904-
if (__signatures.indexOf(s) < 0)
905-
__signatures += s + "\n";
906-
var p = _profile[s];
907-
p || (p = _profile[s] = [0,0,0]);
908-
p[0]++;
909-
p[1] += t1;
910-
p[2] += t2;
911-
}
912-
913883
var addProfileNew = function(c, t) {
914884
var s = c.__CLASS_NAME__;
915885
var p = _profileNew[s];
@@ -4585,10 +4555,11 @@ sp.charCodeAt$I = sp.charCodeAt;
45854555
sp.charAt$I = sp.charAt;
45864556
sp.substring$I = sp.substring$I$I = sp.subSequence$I$I = sp.substring;
45874557
sp.replace$C$C = sp.replace$CharSequence$CharSequence = sp.replace$;
4588-
sp.toUpperCase$ = sp.toUpperCase$java_util_locale = sp.toUpperCase;
4589-
sp.toLowerCase$ = sp.toLowerCase$java_util_locale = sp.toLowerCase;
4558+
sp.toUpperCase$ = sp.toUpperCase;
4559+
sp.toLowerCase$ = sp.toLowerCase;
45904560
sp.trim$ = sp.trim;
4591-
4561+
sp.toLowerCase$java_util_Locale = sp.toLocaleLowerCase ? function(loc) {return this.valueOf().toLocaleLowerCase(loc.toString()) } : sp.toLowerCase;
4562+
sp.toUpperCase$java_util_Locale = sp.toLocaleUpperCase ? function(loc) {return this.valueOf().toLocaleUpperCase(loc.toString()) } : sp.toUpperCase;
45924563
sp.length$ = function() {return this.length};
45934564

45944565
//sp.chars$ = CharSequence.prototype.chars$;

0 commit comments

Comments
 (0)