Skip to content

Commit 85a321a

Browse files
committed
fix
1 parent 290eb2d commit 85a321a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

runtime/js/mlBytes.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,14 @@ var jsoo_text_decoder = new TextDecoder();
300300

301301
//Provides: caml_bytes_of_utf16_jsstring
302302
//Requires: MlBytes, jsoo_text_encoder
303+
//Requires: jsoo_is_ascii
303304
function caml_bytes_of_utf16_jsstring(s) {
304-
var a = jsoo_text_encoder.encode(s);
305-
return new MlBytes(4, a, a.length);
305+
if (jsoo_is_ascii(s)) {
306+
return new MlBytes(9, s, s.length);
307+
} else {
308+
var a = jsoo_text_encoder.encode(s);
309+
return new MlBytes(4, a, a.length);
310+
}
306311
}
307312

308313
//Provides: MlBytes
@@ -687,8 +692,10 @@ function caml_jsstring_of_string(s) {
687692
//Provides: caml_string_of_jsstring const
688693
//Requires: caml_string_of_array
689694
//Requires: jsoo_text_encoder
695+
//Requires: jsoo_is_ascii, caml_string_of_jsbytes
690696
//If: js-string
691697
function caml_string_of_jsstring(s) {
698+
if (jsoo_is_ascii(s)) return caml_string_of_jsbytes(s);
692699
var a = jsoo_text_encoder.encode(s);
693700
return caml_string_of_array(a);
694701
}

0 commit comments

Comments
 (0)