Skip to content

Commit 9724287

Browse files
committed
fix
1 parent 5ef931e commit 9724287

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
@@ -286,9 +286,14 @@ var jsoo_text_decoder = new TextDecoder();
286286

287287
//Provides: caml_bytes_of_utf16_jsstring
288288
//Requires: MlBytes, jsoo_text_encoder
289+
//Requires: jsoo_is_ascii
289290
function caml_bytes_of_utf16_jsstring(s) {
290-
var a = jsoo_text_encoder.encode(s);
291-
return new MlBytes(4, a, a.length);
291+
if (jsoo_is_ascii(s)) {
292+
return new MlBytes(9, s, s.length);
293+
} else {
294+
var a = jsoo_text_encoder.encode(s);
295+
return new MlBytes(4, a, a.length);
296+
}
292297
}
293298

294299
//Provides: MlBytes
@@ -648,8 +653,10 @@ function caml_jsstring_of_string(s) {
648653
//Provides: caml_string_of_jsstring const
649654
//Requires: caml_string_of_array
650655
//Requires: jsoo_text_encoder
656+
//Requires: jsoo_is_ascii, caml_string_of_jsbytes
651657
//If: js-string
652658
function caml_string_of_jsstring(s) {
659+
if (jsoo_is_ascii(s)) return caml_string_of_jsbytes(s);
653660
var a = jsoo_text_encoder.encode(s);
654661
return caml_string_of_array(a);
655662
}

0 commit comments

Comments
 (0)