Skip to content

Commit 88d0e4c

Browse files
committed
Performance improvement with better optimizable JavaScript
1 parent 64b1a3a commit 88d0e4c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/de/inetsoftware/jwebassembly/api/java/lang/ReplacementForString.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,20 @@ private static String newFromSubBytes( byte[] bytes, int offset, int length ) {
6666
/**
6767
* Replacement for new String(char[])
6868
*/
69-
@Import( name = "newFromChars", js = "(value)=>String.fromCharCode.apply(null,value)" )
7069
@Replace( "java/lang/String.<init>([C)V" )
7170
static String newFromChars(char[] value) {
72-
return null; // for compiler
71+
return newFromSubChars( value, 0, value.length ); // for compiler
7372
}
7473

7574
/**
7675
* Replacement for new String(char[],int,int)
7776
*/
78-
@Import( name = "newFromSubChars", js = "(value,off,count)=>String.fromCharCode.apply(null,value.subarray(off,off+count))")
77+
@Import( name = "newFromSubChars", js = "(value,off,count)=>{" + //
78+
"var s='';" + //
79+
"for(var i=off;i<off+count;i++){" + //
80+
"s+=String.fromCharCode(value[i]);" + //
81+
"}" + //
82+
"return s}" )
7983
@Replace( "java/lang/String.<init>([CII)V" )
8084
static String newFromSubChars(char[] value, int offset, int count) {
8185
return null; // for compiler

0 commit comments

Comments
 (0)