@@ -320,17 +320,23 @@ function caml_bytes_set(s, i, c) {
320
320
return caml_bytes_unsafe_set ( s , i , c ) ;
321
321
}
322
322
323
+ //Provides: jsoo_text_encoder
324
+ var jsoo_text_encoder = new TextEncoder ( ) ;
325
+
326
+ //Provides: jsoo_text_decoder
327
+ var jsoo_text_decoder = new TextDecoder ( ) ;
328
+
323
329
//Provides: caml_bytes_of_utf16_jsstring
324
- //Requires: MlBytes
330
+ //Requires: MlBytes, jsoo_text_encoder
325
331
function caml_bytes_of_utf16_jsstring ( s ) {
326
- var e = new TextEncoder ( ) ;
327
- var a = e . encode ( s ) ;
332
+ var a = jsoo_text_encoder . encode ( s ) ;
328
333
return new MlBytes ( 4 , a , a . length ) ;
329
334
}
330
335
331
336
//Provides: MlBytes
332
337
//Requires: caml_convert_string_to_bytes, jsoo_is_ascii
333
338
//Requires: caml_uint8_array_of_bytes
339
+ //Requires: jsoo_text_decoder
334
340
function MlBytes ( tag , contents , length ) {
335
341
this . t = tag ; this . c = contents ; this . l = length ;
336
342
}
@@ -353,8 +359,7 @@ MlBytes.prototype.toString = function () {
353
359
MlBytes . prototype . toUtf16 = function ( ) {
354
360
if ( this . t == 9 ) return this . c ;
355
361
var a = caml_uint8_array_of_bytes ( this ) ;
356
- let d = new TextDecoder ( ) ;
357
- return d . decode ( a ) ;
362
+ return jsoo_text_decoder . decode ( a ) ;
358
363
}
359
364
MlBytes . prototype . slice = function ( ) {
360
365
var content = this . t == 4 ? this . c . slice ( ) : this . c ;
@@ -668,25 +673,32 @@ function caml_jsbytes_of_string(x) {
668
673
return x ;
669
674
}
670
675
676
+ //Provides: jsoo_text_decoder_buff
677
+ var jsoo_text_decoder_buff = new ArrayBuffer ( 1024 ) ;
678
+
671
679
//Provides: caml_jsstring_of_string const
672
680
//Requires: jsoo_is_ascii
681
+ //Requires: jsoo_text_decoder
682
+ //Requires: jsoo_text_decoder_buff
673
683
//If: js-string
674
684
function caml_jsstring_of_string ( s ) {
675
685
if ( jsoo_is_ascii ( s ) ) return s ;
676
- var a = new Uint8Array ( s . length ) ;
686
+ var a =
687
+ ( s . length <= jsoo_text_decoder_buff . length )
688
+ ? Uint8Array ( jsoo_text_decoder_buff , 0 , s . length )
689
+ : ( new Uint8Array ( s . length ) ) ;
677
690
for ( var i = 0 ; i < s . length ; i ++ ) {
678
691
a [ i ] = s . charCodeAt ( i ) ;
679
692
}
680
- var d = new TextDecoder ( ) ;
681
- return d . decode ( a ) ;
693
+ return jsoo_text_decoder . decode ( a ) ;
682
694
}
683
695
684
696
//Provides: caml_string_of_jsstring const
685
697
//Requires: caml_string_of_array
698
+ //Requires: jsoo_text_encoder
686
699
//If: js-string
687
700
function caml_string_of_jsstring ( s ) {
688
- var e = new TextEncoder ( ) ;
689
- var a = e . encode ( s ) ;
701
+ var a = jsoo_text_encoder . encode ( s ) ;
690
702
return caml_string_of_array ( a ) ;
691
703
}
692
704
0 commit comments