Skip to content

Commit 4aa9c61

Browse files
committed
simplify: avoid referring runtime dir
1 parent 818fd84 commit 4aa9c61

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

jscomp/stdlib-406/bytes.ml

+15-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
These functions have a "duplicated" comment above their definition.
2222
*)
2323

24+
25+
26+
external of_small_int_array :
27+
(_ [@bs.as {json|null|json}] ) ->
28+
int array -> string =
29+
"String.fromCharCode.apply"
30+
[@@bs.val]
31+
32+
external (.!()) : string -> int -> char = "%string_unsafe_get"
2433
external length : bytes -> int = "%bytes_length"
2534
external%private string_length : string -> int = "%string_length"
2635
external get : bytes -> int -> char = "%bytes_safe_get"
@@ -86,15 +95,15 @@ let unsafe_blit (s1:bytes) i1 (s2:bytes) i2 len =
8695

8796
let unsafe_blit_string (s1 : string) i1 (s2 : bytes) i2 (len : int ) =
8897
if len > 0 then
89-
let off1 = Caml_string_extern.length s1 - i1 in
98+
let off1 = string_length s1 - i1 in
9099
if len <= off1 then
91100
for i = 0 to len - 1 do
92-
s2.![i2 + i] <- Caml_string_extern.unsafe_get s1 (i1 + i)
101+
s2.![i2 + i] <- s1.!(i1 + i)
93102
done
94103
else
95104
begin
96105
for i = 0 to off1 - 1 do
97-
s2.![i2 + i] <- Caml_string_extern.unsafe_get s1 (i1 + i)
106+
s2.![i2 + i] <- s1.!(i1 + i)
98107
done;
99108
for i = off1 to len - 1 do
100109
s2.![i2 + i] <- '\000'
@@ -105,7 +114,7 @@ let string_of_large_bytes (bytes : bytes) i len =
105114
let s_len = ref len in
106115
let seg = 1024 in
107116
if i = 0 && len <= 4 * seg && len = length bytes then
108-
Caml_string_extern.of_small_int_array (to_int_array bytes)
117+
of_small_int_array (to_int_array bytes)
109118
else
110119
begin
111120
let offset = ref 0 in
@@ -115,7 +124,7 @@ let string_of_large_bytes (bytes : bytes) i len =
115124
for k = 0 to next - 1 do
116125
tmp_bytes.![k] <- bytes.![k + offset.contents]
117126
done;
118-
s.contents <- s.contents ^ Caml_string_extern.of_small_int_array (to_int_array tmp_bytes);
127+
s.contents <- s.contents ^ of_small_int_array (to_int_array tmp_bytes);
119128
s_len.contents <- s_len.contents - next ;
120129
offset.contents <- offset.contents + next;
121130
done;
@@ -153,7 +162,7 @@ let of_string (s : string) =
153162
let len = string_length s in
154163
let res = new_uninitialized len in
155164
for i = 0 to len - 1 do
156-
res.![i] <- Caml_string_extern.unsafe_get s i
165+
res.![i] <- s.!(i)
157166
(* Note that when get a char and convert it to int immedately, should be optimized
158167
should be [s.charCodeAt[i]]
159168
*)

jscomp/stdlib-406/bytesLabels.ml

+12-6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
modify its duplicate in string.ml.
2121
These functions have a "duplicated" comment above their definition.
2222
*)
23+
external (.!()) : string -> int -> char = "%string_unsafe_get"
24+
external of_small_int_array :
25+
(_ [@bs.as {json|null|json}] ) ->
26+
int array -> string =
27+
"String.fromCharCode.apply"
28+
[@@bs.val]
2329

2430
external length : bytes -> int = "%bytes_length"
2531
external%private string_length : string -> int = "%string_length"
@@ -86,15 +92,15 @@ let unsafe_blit (s1:bytes) i1 (s2:bytes) i2 len =
8692

8793
let unsafe_blit_string (s1 : string) i1 (s2 : bytes) i2 (len : int ) =
8894
if len > 0 then
89-
let off1 = Caml_string_extern.length s1 - i1 in
95+
let off1 = string_length s1 - i1 in
9096
if len <= off1 then
9197
for i = 0 to len - 1 do
92-
s2.![i2 + i] <- Caml_string_extern.unsafe_get s1 (i1 + i)
98+
s2.![i2 + i] <- s1.!(i1 + i)
9399
done
94100
else
95101
begin
96102
for i = 0 to off1 - 1 do
97-
s2.![i2 + i] <- Caml_string_extern.unsafe_get s1 (i1 + i)
103+
s2.![i2 + i] <- s1.!(i1 + i)
98104
done;
99105
for i = off1 to len - 1 do
100106
s2.![i2 + i] <- '\000'
@@ -105,7 +111,7 @@ let string_of_large_bytes (bytes : bytes) i len =
105111
let s_len = ref len in
106112
let seg = 1024 in
107113
if i = 0 && len <= 4 * seg && len = length bytes then
108-
Caml_string_extern.of_small_int_array (to_int_array bytes)
114+
of_small_int_array (to_int_array bytes)
109115
else
110116
begin
111117
let offset = ref 0 in
@@ -115,7 +121,7 @@ let string_of_large_bytes (bytes : bytes) i len =
115121
for k = 0 to next - 1 do
116122
tmp_bytes.![k] <- bytes.![k + offset.contents]
117123
done;
118-
s.contents <- s.contents ^ Caml_string_extern.of_small_int_array (to_int_array tmp_bytes);
124+
s.contents <- s.contents ^ of_small_int_array (to_int_array tmp_bytes);
119125
s_len.contents <- s_len.contents - next ;
120126
offset.contents <- offset.contents + next;
121127
done;
@@ -153,7 +159,7 @@ let of_string (s : string) =
153159
let len = string_length s in
154160
let res = new_uninitialized len in
155161
for i = 0 to len - 1 do
156-
res.![i] <- Caml_string_extern.unsafe_get s i
162+
res.![i] <- s.!(i)
157163
(* Note that when get a char and convert it to int immedately, should be optimized
158164
should be [s.charCodeAt[i]]
159165
*)

0 commit comments

Comments
 (0)