Skip to content

Commit 46c1a1c

Browse files
committed
remove caml_queue
1 parent 6eaec17 commit 46c1a1c

File tree

7 files changed

+113
-201
lines changed

7 files changed

+113
-201
lines changed

Diff for: jscomp/runtime/.depend

+8-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ caml_obj.cmi : js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_obj_extern.cmj
1717
caml_oo.cmi : js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
1818
caml_parser.cmi : js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_obj_extern.cmj
1919
caml_primitive.cmi : js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
20-
caml_queue.cmi : js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
2120
caml_string.cmi : js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
2221
caml_sys.cmi : js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
2322
caml_utils.cmi : js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
@@ -28,13 +27,14 @@ caml_array.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_builtin
2827
caml_array_extern.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
2928
caml_builtin_exceptions.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_obj_extern.cmj caml_builtin_exceptions.cmi
3029
caml_bytes.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_builtin_exceptions.cmj caml_bytes.cmi caml_string_extern.cmj caml_bytes_extern.cmj
30+
caml_bytes_extern.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
3131
caml_char.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
3232
caml_exceptions.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_obj_extern.cmj caml_nativeint_extern.cmj caml_builtin_exceptions.cmj caml_exceptions.cmi
3333
caml_float.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_float_extern.cmj caml_float.cmi
3434
caml_float_extern.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
3535
caml_format.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_int32.cmj caml_int64.cmj caml_utils.cmj caml_builtin_exceptions.cmj caml_format.cmi caml_string_extern.cmj caml_nativeint_extern.cmj caml_int64_extern.cmj caml_float_extern.cmj caml_float.cmj caml_char.cmj
3636
caml_gc.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_gc.cmi
37-
caml_hash.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_queue.cmj caml_hash_primitive.cmj caml_builtin_exceptions.cmj caml_hash.cmi caml_obj_extern.cmj caml_nativeint_extern.cmj
37+
caml_hash.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_hash_primitive.cmj caml_builtin_exceptions.cmj caml_hash.cmi caml_undefined_extern.cmj caml_obj_extern.cmj caml_nativeint_extern.cmj
3838
caml_hash_primitive.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_int32.cmj caml_hash_primitive.cmi caml_string_extern.cmj caml_nativeint_extern.cmj caml_char.cmj
3939
caml_int32.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_builtin_exceptions.cmj caml_int32.cmi caml_nativeint_extern.cmj
4040
caml_int32_extern.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
@@ -43,25 +43,24 @@ caml_int64_extern.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
4343
caml_io.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe curry.cmj caml_builtin_exceptions.cmj caml_undefined_extern.cmj caml_string_extern.cmj
4444
caml_js_exceptions.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe js_primitive.cmj caml_exceptions.cmj caml_obj_extern.cmj
4545
caml_lexer.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_builtin_exceptions.cmj caml_lexer.cmi
46-
caml_md5.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_string_extern.cmj caml_int32_extern.cmj caml_char.cmj caml_array.cmj caml_md5.cmi caml_array_extern.cmj
46+
caml_md5.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_string_extern.cmj caml_int32_extern.cmj caml_char.cmj caml_array_extern.cmj caml_md5.cmi
4747
caml_missing_polyfill.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_missing_polyfill.cmi
48-
caml_module.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_obj.cmj caml_builtin_exceptions.cmj caml_obj_extern.cmj caml_array.cmj caml_array_extern.cmj
48+
caml_module.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_obj.cmj caml_builtin_exceptions.cmj caml_obj_extern.cmj caml_array_extern.cmj
4949
caml_nativeint_extern.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
50-
caml_obj.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe block.cmj caml_primitive.cmj caml_builtin_exceptions.cmj caml_obj.cmi caml_obj_extern.cmj caml_array.cmj caml_array_extern.cmj
50+
caml_obj.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe block.cmj caml_primitive.cmj caml_builtin_exceptions.cmj caml_obj.cmi caml_obj_extern.cmj caml_array_extern.cmj
5151
caml_obj_extern.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
5252
caml_oo.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_array.cmj caml_builtin_exceptions.cmj caml_oo.cmi caml_obj_extern.cmj caml_array_extern.cmj
5353
caml_oo_curry.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe curry.cmj caml_oo.cmj
5454
caml_parser.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_obj_extern.cmj caml_parser.cmi
55-
caml_primitive.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_bytes.cmj caml_primitive.cmi caml_bytes_extern.cmj
56-
caml_queue.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_queue.cmi
55+
caml_primitive.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_bytes_extern.cmj caml_primitive.cmi
5756
caml_string.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_builtin_exceptions.cmj caml_string.cmi caml_string_extern.cmj caml_char.cmj
5857
caml_string_extern.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
59-
caml_sys.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_builtin_exceptions.cmj caml_sys.cmi caml_undefined_extern.cmj caml_nativeint_extern.cmj caml_array.cmj caml_array_extern.cmj
58+
caml_sys.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_builtin_exceptions.cmj caml_sys.cmi caml_undefined_extern.cmj caml_nativeint_extern.cmj caml_array_extern.cmj
6059
caml_undefined_extern.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe
6160
caml_utils.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_utils.cmi
6261
caml_weak.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_obj.cmj caml_array.cmj js_primitive.cmj caml_weak.cmi caml_undefined_extern.cmj caml_obj_extern.cmj caml_array_extern.cmj
6362
curry.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_array.cmj caml_array_extern.cmj
6463
js_primitive.cmj : js.cmj js.cmi bs_stdlib_mini.cmi ../../lib/bsc.exe caml_undefined_extern.cmj caml_obj_extern.cmj js_primitive.cmi
65-
all : block.cmi caml_array.cmi caml_builtin_exceptions.cmi caml_bytes.cmi caml_exceptions.cmi caml_float.cmi caml_format.cmi caml_gc.cmi caml_hash.cmi caml_hash_primitive.cmi caml_int32.cmi caml_int64.cmi caml_lexer.cmi caml_md5.cmi caml_missing_polyfill.cmi caml_obj.cmi caml_oo.cmi caml_parser.cmi caml_primitive.cmi caml_queue.cmi caml_string.cmi caml_sys.cmi caml_utils.cmi caml_weak.cmi js_primitive.cmi block.cmj caml_array.cmj caml_array_extern.cmj caml_builtin_exceptions.cmj caml_bytes.cmj caml_char.cmj caml_exceptions.cmj caml_float.cmj caml_float_extern.cmj caml_format.cmj caml_gc.cmj caml_hash.cmj caml_hash_primitive.cmj caml_int32.cmj caml_int32_extern.cmj caml_int64.cmj caml_int64_extern.cmj caml_io.cmj caml_js_exceptions.cmj caml_lexer.cmj caml_md5.cmj caml_missing_polyfill.cmj caml_module.cmj caml_nativeint_extern.cmj caml_obj.cmj caml_obj_extern.cmj caml_oo.cmj caml_oo_curry.cmj caml_parser.cmj caml_primitive.cmj caml_queue.cmj caml_string.cmj caml_string_extern.cmj caml_sys.cmj caml_undefined_extern.cmj caml_utils.cmj caml_weak.cmj curry.cmj js_primitive.cmj js.cmj js.cmi
64+
all : block.cmi caml_array.cmi caml_builtin_exceptions.cmi caml_bytes.cmi caml_exceptions.cmi caml_float.cmi caml_format.cmi caml_gc.cmi caml_hash.cmi caml_hash_primitive.cmi caml_int32.cmi caml_int64.cmi caml_lexer.cmi caml_md5.cmi caml_missing_polyfill.cmi caml_obj.cmi caml_oo.cmi caml_parser.cmi caml_primitive.cmi caml_string.cmi caml_sys.cmi caml_utils.cmi caml_weak.cmi js_primitive.cmi block.cmj caml_array.cmj caml_array_extern.cmj caml_builtin_exceptions.cmj caml_bytes.cmj caml_bytes_extern.cmj caml_char.cmj caml_exceptions.cmj caml_float.cmj caml_float_extern.cmj caml_format.cmj caml_gc.cmj caml_hash.cmj caml_hash_primitive.cmj caml_int32.cmj caml_int32_extern.cmj caml_int64.cmj caml_int64_extern.cmj caml_io.cmj caml_js_exceptions.cmj caml_lexer.cmj caml_md5.cmj caml_missing_polyfill.cmj caml_module.cmj caml_nativeint_extern.cmj caml_obj.cmj caml_obj_extern.cmj caml_oo.cmj caml_oo_curry.cmj caml_parser.cmj caml_primitive.cmj caml_string.cmj caml_string_extern.cmj caml_sys.cmj caml_undefined_extern.cmj caml_utils.cmj caml_weak.cmj curry.cmj js_primitive.cmj js.cmj js.cmi
6665
js.cmj : ../../lib/bsc.exe js.cmi
6766
js.cmi : ../../lib/bsc.exe bs_stdlib_mini.cmi

Diff for: jscomp/runtime/caml_array_extern.ml

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ external unsafe_get : 'a array -> int -> 'a = "%array_unsafe_get"
66
external unsafe_set : 'a array -> int -> 'a -> unit = "%array_unsafe_set"
77
external length : 'a array -> int = "%array_length"
88

9-
external caml_array_dup : 'a array -> (_ [@bs.as 0]) -> 'a array =
10-
"slice" [@@bs.send]
119

1210
(*
1311
Could be replaced by {!Caml_array.caml_make_vect}

Diff for: jscomp/runtime/caml_hash.ml

+59-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,58 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25+
type 'a cell = {
26+
content : 'a ;
27+
mutable next : 'a cell_opt
28+
}
29+
and 'a cell_opt = 'a cell Caml_undefined_extern.t
30+
and 'a t = {
31+
mutable length : int ;
32+
mutable first : 'a cell_opt;
33+
mutable last : 'a cell_opt
34+
}
35+
[@@bs.deriving abstract]
36+
37+
let create_queue () =
38+
t
39+
~length:0
40+
~first:Caml_undefined_extern.empty
41+
~last:Caml_undefined_extern.empty
42+
43+
(* Added to tail *)
44+
let push_back (q :'a t) (v : 'a) =
45+
let cell =
46+
Caml_undefined_extern.return @@
47+
cell
48+
~content:v ~next:Caml_undefined_extern.empty
49+
in
50+
match q |. lastGet |. Caml_undefined_extern.toOption with
51+
| None ->
52+
q |. lengthSet 1 ;
53+
q |. firstSet cell;
54+
q |. lastSet cell
55+
| Some last ->
56+
q |. lengthSet ((q |. lengthGet) + 1);
57+
last |. nextSet cell;
58+
q |. lastSet cell
59+
60+
let is_empty_queue q = q |. lengthGet = 0
61+
62+
(* pop from front *)
63+
let unsafe_pop (q : 'a t) =
64+
let cell = (Obj.magic (q |. firstGet) : 'a cell) in
65+
let content, next_cell = cell |. (contentGet, nextGet) in
66+
match Caml_undefined_extern.toOption next_cell with
67+
| None ->
68+
q |. lengthSet 0 ;
69+
q |. firstSet Caml_undefined_extern.empty;
70+
q |. lastSet Caml_undefined_extern.empty;
71+
content
72+
| Some next ->
73+
q |. lengthSet ((q |. lengthGet) - 1);
74+
q |. firstSet next_cell ;
75+
content
76+
2577

2678

2779
external ( +~ ) : nativeint -> nativeint -> nativeint =
@@ -32,7 +84,8 @@ external oo_id : Caml_obj_extern.t -> int = "%field1"
3284

3385
open Caml_hash_primitive
3486

35-
let caml_hash count _limit seed obj =
87+
let caml_hash (count : int) _limit (seed : nativeint)
88+
(obj : Caml_obj_extern.t) : nativeint =
3689
let hash = ref seed in
3790
if Js.typeof obj = "number" then
3891
begin
@@ -48,14 +101,14 @@ let caml_hash count _limit seed obj =
48101
(* TODO: hash [null] [undefined] as well *)
49102
else
50103

51-
let queue = Caml_queue.create () in
104+
let queue = create_queue () in
52105
let num = ref count in
53106
let () =
54-
Caml_queue.push obj queue;
107+
push_back queue obj;
55108
decr num
56109
in
57-
while not (Caml_queue.is_empty queue) && !num > 0 do
58-
let obj = Caml_queue.unsafe_pop queue in
110+
while not ( is_empty_queue queue) && !num > 0 do
111+
let obj = unsafe_pop queue in
59112
if Js.typeof obj = "number" then
60113
begin
61114
let u = Caml_nativeint_extern.of_float (Obj.magic obj) in
@@ -90,7 +143,7 @@ let caml_hash count _limit seed obj =
90143
let block =
91144
let v = size - 1 in if v < !num then v else !num in
92145
for i = 0 to block do
93-
Caml_queue.push (Caml_obj_extern.field obj i ) queue
146+
push_back queue (Caml_obj_extern.field obj i )
94147
done
95148
end
96149
done;

Diff for: jscomp/runtime/caml_queue.ml

-83
This file was deleted.

Diff for: jscomp/runtime/caml_queue.mli

-38
This file was deleted.

Diff for: lib/js/caml_hash.js

+45-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
11
'use strict';
22

3-
var Caml_queue = require("./caml_queue.js");
43
var Caml_hash_primitive = require("./caml_hash_primitive.js");
54
var Caml_builtin_exceptions = require("./caml_builtin_exceptions.js");
65

6+
function push_back(q, v) {
7+
var cell = {
8+
content: v,
9+
next: undefined
10+
};
11+
var match = q.last;
12+
if (match !== undefined) {
13+
q.length = q.length + 1 | 0;
14+
match.next = cell;
15+
q.last = cell;
16+
return /* () */0;
17+
} else {
18+
q.length = 1;
19+
q.first = cell;
20+
q.last = cell;
21+
return /* () */0;
22+
}
23+
}
24+
25+
function unsafe_pop(q) {
26+
var cell = q.first;
27+
var content = cell.content;
28+
var next_cell = cell.next;
29+
if (next_cell !== undefined) {
30+
q.length = q.length - 1 | 0;
31+
q.first = next_cell;
32+
return content;
33+
} else {
34+
q.length = 0;
35+
q.first = undefined;
36+
q.last = undefined;
37+
return content;
38+
}
39+
}
40+
741
function caml_hash(count, _limit, seed, obj) {
842
var hash = seed;
943
if (typeof obj === "number") {
@@ -14,15 +48,16 @@ function caml_hash(count, _limit, seed, obj) {
1448
hash = Caml_hash_primitive.caml_hash_mix_string(hash, obj);
1549
return Caml_hash_primitive.caml_hash_final_mix(hash);
1650
} else {
17-
var queue = /* record */[
18-
/* length */0,
19-
/* tail */undefined
20-
];
51+
var queue = {
52+
length: 0,
53+
first: undefined,
54+
last: undefined
55+
};
2156
var num = count;
22-
Caml_queue.push(obj, queue);
57+
push_back(queue, obj);
2358
num = num - 1 | 0;
24-
while(queue[/* length */0] !== 0 && num > 0) {
25-
var obj$1 = Caml_queue.unsafe_pop(queue);
59+
while(queue.length !== 0 && num > 0) {
60+
var obj$1 = unsafe_pop(queue);
2661
if (typeof obj$1 === "number") {
2762
var u$1 = obj$1 | 0;
2863
hash = Caml_hash_primitive.caml_hash_mix_int(hash, (u$1 + u$1 | 0) + 1 | 0);
@@ -37,7 +72,7 @@ function caml_hash(count, _limit, seed, obj) {
3772
Caml_builtin_exceptions.assert_failure,
3873
/* tuple */[
3974
"caml_hash.ml",
40-
75,
75+
128,
4176
8
4277
]
4378
];
@@ -53,7 +88,7 @@ function caml_hash(count, _limit, seed, obj) {
5388
var v = size - 1 | 0;
5489
var block = v < num ? v : num;
5590
for(var i = 0; i <= block; ++i){
56-
Caml_queue.push(obj$1[i], queue);
91+
push_back(queue, obj$1[i]);
5792
}
5893
}
5994
}

0 commit comments

Comments
 (0)