@@ -69,19 +69,15 @@ external mutableCell :
69
69
'a -> 'a t -> 'a t = " #makemutablelist"
70
70
71
71
72
- type poly = { unsafeMutateTail : 'a . 'a t -> 'a t -> unit } [@@ unboxed]
73
-
74
-
75
72
(*
76
73
[mutableCell x []] == [x]
77
74
but tell the compiler that is a mutable cell, so it wont
78
75
be mis-inlined in the future
79
76
dont inline a binding to mutable cell, it is mutable
80
77
*)
81
- (* relies on list internal representation *)
82
- let m : poly = {unsafeMutateTail = [% raw{| function(xs,ys){
83
- xs.tl = ys
84
- }| }]}
78
+ (* INVARIANT: relies on Literals.tl (internal representation) *)
79
+ external unsafeMutateTail : 'a t -> 'a t -> unit = " tl" [@@ bs.set]
80
+
85
81
86
82
87
83
@@ -137,12 +133,12 @@ let rec partitionAux p cell precX precY =
137
133
let next = mutableCell h [] in
138
134
if p h [@ bs] then
139
135
begin
140
- m. unsafeMutateTail precX next ;
136
+ unsafeMutateTail precX next ;
141
137
partitionAux p t next precY
142
138
end
143
139
else
144
140
begin
145
- m. unsafeMutateTail precY next ;
141
+ unsafeMutateTail precY next ;
146
142
partitionAux p t precX next
147
143
end
148
144
@@ -152,8 +148,8 @@ let rec splitAux cell precX precY =
152
148
| (a ,b )::t ->
153
149
let nextA = mutableCell a [] in
154
150
let nextB = mutableCell b [] in
155
- m. unsafeMutateTail precX nextA;
156
- m. unsafeMutateTail precY nextB;
151
+ unsafeMutateTail precX nextA;
152
+ unsafeMutateTail precY nextB;
157
153
splitAux t nextA nextB
158
154
159
155
(* return the tail pointer so it can continue copy other
@@ -164,7 +160,7 @@ let rec copyAuxCont cellX prec =
164
160
| [] -> prec
165
161
| h ::t ->
166
162
let next = mutableCell h [] in
167
- m. unsafeMutateTail prec next ;
163
+ unsafeMutateTail prec next ;
168
164
copyAuxCont t next
169
165
170
166
let rec copyAuxWitFilter f cellX prec =
@@ -175,7 +171,7 @@ let rec copyAuxWitFilter f cellX prec =
175
171
if f h [@ bs] then
176
172
begin
177
173
let next = mutableCell h [] in
178
- m. unsafeMutateTail prec next ;
174
+ unsafeMutateTail prec next ;
179
175
copyAuxWitFilter f t next
180
176
end
181
177
else copyAuxWitFilter f t prec
@@ -188,7 +184,7 @@ let rec copyAuxWithFilterIndex f cellX prec i =
188
184
if f h i [@ bs] then
189
185
begin
190
186
let next = mutableCell h [] in
191
- m. unsafeMutateTail prec next ;
187
+ unsafeMutateTail prec next ;
192
188
copyAuxWithFilterIndex f t next (i + 1 )
193
189
end
194
190
else copyAuxWithFilterIndex f t prec (i + 1 )
@@ -202,7 +198,7 @@ let rec copyAuxWitFilterMap f cellX prec =
202
198
| Some h ->
203
199
begin
204
200
let next = mutableCell h [] in
205
- m. unsafeMutateTail prec next ;
201
+ unsafeMutateTail prec next ;
206
202
copyAuxWitFilterMap f t next
207
203
end
208
204
| None -> copyAuxWitFilterMap f t prec
@@ -212,21 +208,21 @@ let rec removeAssocAuxWithMap cellX x prec f =
212
208
| [] -> false
213
209
| ((a ,_ ) as h ):: t ->
214
210
if f a x [@ bs] then
215
- (m. unsafeMutateTail prec t ; true )
211
+ (unsafeMutateTail prec t ; true )
216
212
else
217
213
let next = mutableCell h [] in
218
- m. unsafeMutateTail prec next ;
214
+ unsafeMutateTail prec next ;
219
215
removeAssocAuxWithMap t x next f
220
216
221
217
let rec setAssocAuxWithMap cellX x k prec eq =
222
218
match cellX with
223
219
| [] -> false
224
220
| ((a ,_ ) as h ) :: t ->
225
221
if eq a x [@ bs] then
226
- (m. unsafeMutateTail prec ( (x,k)::t); true )
222
+ (unsafeMutateTail prec ( (x,k)::t); true )
227
223
else
228
224
let next = mutableCell h [] in
229
- m. unsafeMutateTail prec next ;
225
+ unsafeMutateTail prec next ;
230
226
setAssocAuxWithMap t x k next eq
231
227
232
228
@@ -236,15 +232,15 @@ let rec copyAuxWithMap cellX prec f =
236
232
()
237
233
| h ::t ->
238
234
let next = mutableCell (f h [@ bs]) [] in
239
- m. unsafeMutateTail prec next ;
235
+ unsafeMutateTail prec next ;
240
236
copyAuxWithMap t next f
241
237
242
238
243
239
let rec zipAux cellX cellY prec =
244
240
match cellX, cellY with
245
241
| h1 ::t1 , h2 ::t2 ->
246
242
let next = mutableCell ( h1, h2) [] in
247
- m. unsafeMutateTail prec next ;
243
+ unsafeMutateTail prec next ;
248
244
zipAux t1 t2 next
249
245
| [] ,_ | _ ,[] ->
250
246
()
@@ -253,7 +249,7 @@ let rec copyAuxWithMap2 f cellX cellY prec =
253
249
match cellX, cellY with
254
250
| h1 ::t1 , h2 ::t2 ->
255
251
let next = mutableCell (f h1 h2 [@ bs]) [] in
256
- m. unsafeMutateTail prec next ;
252
+ unsafeMutateTail prec next ;
257
253
copyAuxWithMap2 f t1 t2 next
258
254
| [] ,_ | _ ,[] ->
259
255
()
@@ -262,7 +258,7 @@ let rec copyAuxWithMapI f i cellX prec =
262
258
match cellX with
263
259
| h ::t ->
264
260
let next = mutableCell (f i h [@ bs]) [] in
265
- m. unsafeMutateTail prec next ;
261
+ unsafeMutateTail prec next ;
266
262
copyAuxWithMapI f (i + 1 ) t next
267
263
| [] ->
268
264
()
@@ -274,7 +270,7 @@ let rec takeAux n cell prec =
274
270
| [] -> false
275
271
| x ::xs ->
276
272
let cell = mutableCell x [] in
277
- m. unsafeMutateTail prec cell;
273
+ unsafeMutateTail prec cell;
278
274
takeAux (n - 1 ) xs cell
279
275
280
276
let rec splitAtAux n cell prec =
@@ -284,7 +280,7 @@ let rec splitAtAux n cell prec =
284
280
| [] -> None
285
281
| x ::xs ->
286
282
let cell = mutableCell x [] in
287
- m. unsafeMutateTail prec cell;
283
+ unsafeMutateTail prec cell;
288
284
splitAtAux (n - 1 ) xs cell
289
285
290
286
(* invarint [n >= 0] *)
@@ -332,7 +328,7 @@ let concat xs ys =
332
328
| [] -> ys
333
329
| h ::t ->
334
330
let cell = mutableCell h [] in
335
- m. unsafeMutateTail (copyAuxCont t cell) ys;
331
+ unsafeMutateTail (copyAuxCont t cell) ys;
336
332
cell
337
333
338
334
let mapU xs f =
@@ -374,7 +370,7 @@ let makeByU n f =
374
370
let i = ref 1 in
375
371
while i.contents < n do
376
372
let v = mutableCell (f i.contents [@ bs]) [] in
377
- m. unsafeMutateTail cur.contents v ;
373
+ unsafeMutateTail cur.contents v ;
378
374
cur.contents< - v ;
379
375
i.contents < - i.contents + 1 ;
380
376
done
@@ -391,7 +387,7 @@ let make (type a) n (v : a) : a list =
391
387
let i = ref 1 in
392
388
while i.contents < n do
393
389
let v = mutableCell v [] in
394
- m. unsafeMutateTail cur.contents v ;
390
+ unsafeMutateTail cur.contents v ;
395
391
cur.contents< - v ;
396
392
i.contents < - i.contents + 1 ;
397
393
done
@@ -477,7 +473,7 @@ let reverse l = reverseConcat l []
477
473
478
474
let rec flattenAux prec xs =
479
475
match xs with
480
- | [] -> m. unsafeMutateTail prec []
476
+ | [] ->unsafeMutateTail prec []
481
477
| h ::r -> flattenAux (copyAuxCont h prec) r
482
478
483
479
0 commit comments