Skip to content

Commit 5fcbeec

Browse files
committed
fix
1 parent 638af31 commit 5fcbeec

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

284284
//Provides: caml_bytes_of_utf16_jsstring
285285
//Requires: MlBytes, jsoo_text_encoder
286+
//Requires: jsoo_is_ascii
286287
function caml_bytes_of_utf16_jsstring(s) {
287-
var a = jsoo_text_encoder.encode(s);
288-
return new MlBytes(4, a, a.length);
288+
if (jsoo_is_ascii(s)) {
289+
return new MlBytes(9, s, s.length);
290+
} else {
291+
var a = jsoo_text_encoder.encode(s);
292+
return new MlBytes(4, a, a.length);
293+
}
289294
}
290295

291296
//Provides: MlBytes
@@ -670,8 +675,10 @@ function caml_jsstring_of_string(s) {
670675
//Provides: caml_string_of_jsstring const
671676
//Requires: caml_string_of_array
672677
//Requires: jsoo_text_encoder
678+
//Requires: jsoo_is_ascii, caml_string_of_jsbytes
673679
//If: js-string
674680
function caml_string_of_jsstring(s) {
681+
if (jsoo_is_ascii(s)) return caml_string_of_jsbytes(s);
675682
var a = jsoo_text_encoder.encode(s);
676683
return caml_string_of_array(a);
677684
}

0 commit comments

Comments
 (0)