@@ -9650,7 +9650,7 @@ reduces them without incurring seq initialization"
9650
9650
(take-while (mk-bound-fn sc start-test start-key)
9651
9651
(if ((mk-bound-fn sc end-test end-key) e) s (next s))))))
9652
9652
9653
- (deftype RangeChunk [start step count]
9653
+ (deftype IntegerRangeChunk [start step count]
9654
9654
ICounted
9655
9655
(-count [coll] count)
9656
9656
@@ -9669,7 +9669,7 @@ reduces them without incurring seq initialization"
9669
9669
(-drop-first [coll]
9670
9670
(if (<= count 1 )
9671
9671
(throw (js/Error. " -drop-first of empty chunk" ))
9672
- (RangeChunk . (+ start step) step (dec count)))))
9672
+ (IntegerRangeChunk . (+ start step) step (dec count)))))
9673
9673
9674
9674
(deftype RangeIterator [^:mutable i end step]
9675
9675
Object
@@ -9682,7 +9682,7 @@ reduces them without incurring seq initialization"
9682
9682
(set! i (+ i step))
9683
9683
ret)))
9684
9684
9685
- (deftype Range [meta start end step ^:mutable chunk ^:mutable chunk-next ^:mutable __hash]
9685
+ (deftype IntegerRange [meta start end step ^:mutable chunk ^:mutable chunk-next ^:mutable __hash]
9686
9686
Object
9687
9687
(toString [coll]
9688
9688
(pr-str* coll))
@@ -9701,18 +9701,18 @@ reduces them without incurring seq initialization"
9701
9701
(let [count (-count coll)]
9702
9702
(if (> count 32 )
9703
9703
(do
9704
- (set! chunk-next (Range . nil (+ start (* step 32 )) end step nil nil nil ))
9705
- (set! chunk (RangeChunk . start step 32 )))
9706
- (set! chunk (RangeChunk . start step count))))))
9704
+ (set! chunk-next (IntegerRange . nil (+ start (* step 32 )) end step nil nil nil ))
9705
+ (set! chunk (IntegerRangeChunk . start step 32 )))
9706
+ (set! chunk (IntegerRangeChunk . start step count))))))
9707
9707
9708
9708
ICloneable
9709
- (-clone [_] (Range . meta start end step chunk chunk-next __hash))
9709
+ (-clone [_] (IntegerRange . meta start end step chunk chunk-next __hash))
9710
9710
9711
9711
IWithMeta
9712
9712
(-with-meta [rng new-meta]
9713
9713
(if (identical? new-meta meta)
9714
9714
rng
9715
- (Range . new-meta start end step chunk chunk-next __hash)))
9715
+ (IntegerRange . new-meta start end step chunk chunk-next __hash)))
9716
9716
9717
9717
IMeta
9718
9718
(-meta [rng] meta)
@@ -9736,9 +9736,9 @@ reduces them without incurring seq initialization"
9736
9736
(-next [rng]
9737
9737
(if (pos? step)
9738
9738
(when (< (+ start step) end)
9739
- (Range . nil (+ start step) end step nil nil nil ))
9739
+ (IntegerRange . nil (+ start step) end step nil nil nil ))
9740
9740
(when (> (+ start step) end)
9741
- (Range . nil (+ start step) end step nil nil nil ))))
9741
+ (IntegerRange . nil (+ start step) end step nil nil nil ))))
9742
9742
9743
9743
IChunkedSeq
9744
9744
(-chunked-first [rng]
@@ -9796,6 +9796,113 @@ reduces them without incurring seq initialization"
9796
9796
(recur (+ i step) ret)))
9797
9797
ret))))
9798
9798
9799
+ (es6-iterable IntegerRange)
9800
+
9801
+ (deftype Range [meta start end step ^:mutable chunk ^:mutable chunk-next ^:mutable __hash]
9802
+ Object
9803
+ (toString [coll]
9804
+ (pr-str* coll))
9805
+ (equiv [this other]
9806
+ (-equiv this other))
9807
+ (indexOf [coll x]
9808
+ (-indexOf coll x 0 ))
9809
+ (indexOf [coll x start]
9810
+ (-indexOf coll x start))
9811
+ (lastIndexOf [coll x]
9812
+ (-lastIndexOf coll x (count coll)))
9813
+ (lastIndexOf [coll x start]
9814
+ (-lastIndexOf coll x start))
9815
+ (forceChunk [coll]
9816
+ (when (nil? chunk)
9817
+ (let [arr (make-array 32 )
9818
+ val (loop [n 0 val start]
9819
+ (if (< n 32 )
9820
+ (do
9821
+ (aset arr n val)
9822
+ (let [n (inc n)
9823
+ val (+ val step)]
9824
+ (if (if (pos? step) (< val end) (> val end))
9825
+ (recur n val)
9826
+ (set! chunk (array-chunk arr 0 n)))))
9827
+ val))]
9828
+ (when (nil? chunk)
9829
+ (set! chunk (array-chunk arr 0 32 ))
9830
+ (when (if (pos? step) (< val end) (> val end))
9831
+ (set! chunk-next (Range. nil val end step nil nil nil )))))))
9832
+
9833
+ ICloneable
9834
+ (-clone [_] (Range. meta start end step chunk chunk-next __hash))
9835
+
9836
+ IWithMeta
9837
+ (-with-meta [rng new-meta]
9838
+ (if (identical? new-meta meta)
9839
+ rng
9840
+ (Range. new-meta start end step chunk chunk-next __hash)))
9841
+
9842
+ IMeta
9843
+ (-meta [rng] meta)
9844
+
9845
+ ISeqable
9846
+ (-seq [rng] rng)
9847
+
9848
+ ISeq
9849
+ (-first [rng] start)
9850
+ (-rest [rng]
9851
+ (let [s (-next rng)]
9852
+ (if (nil? s)
9853
+ ()
9854
+ s)))
9855
+
9856
+ IIterable
9857
+ (-iterator [_]
9858
+ (RangeIterator. start end step))
9859
+
9860
+ INext
9861
+ (-next [rng]
9862
+ (if (pos? step)
9863
+ (when (< (+ start step) end)
9864
+ (Range. nil (+ start step) end step nil nil nil ))
9865
+ (when (> (+ start step) end)
9866
+ (Range. nil (+ start step) end step nil nil nil ))))
9867
+
9868
+ IChunkedSeq
9869
+ (-chunked-first [rng]
9870
+ (.forceChunk rng)
9871
+ chunk)
9872
+ (-chunked-rest [rng]
9873
+ (.forceChunk rng)
9874
+ (if (nil? chunk-next)
9875
+ ()
9876
+ chunk-next))
9877
+
9878
+ IChunkedNext
9879
+ (-chunked-next [rng]
9880
+ (seq (-chunked-rest rng)))
9881
+
9882
+ ICollection
9883
+ (-conj [rng o] (cons o rng))
9884
+
9885
+ IEmptyableCollection
9886
+ (-empty [rng] (.-EMPTY List))
9887
+
9888
+ ISequential
9889
+ IEquiv
9890
+ (-equiv [rng other] (equiv-sequential rng other))
9891
+
9892
+ IHash
9893
+ (-hash [rng] (caching-hash rng hash-ordered-coll __hash))
9894
+
9895
+ IReduce
9896
+ (-reduce [rng f] (seq-reduce f rng))
9897
+ (-reduce [rng f init]
9898
+ (loop [i start ret init]
9899
+ (if (if (pos? step) (< i end) (> i end))
9900
+ (let [ret (f ret i)]
9901
+ (if (reduced? ret)
9902
+ @ret
9903
+ (recur (+ i step) ret)))
9904
+ ret))))
9905
+
9799
9906
(es6-iterable Range)
9800
9907
9801
9908
(defn range
@@ -9810,12 +9917,16 @@ reduces them without incurring seq initialization"
9810
9917
(pos? step)
9811
9918
(if (<= end start)
9812
9919
()
9813
- (Range. nil start end step nil nil nil ))
9920
+ (if (and (integer? start) (integer? end) (integer? step))
9921
+ (IntegerRange. nil start end step nil nil nil )
9922
+ (Range. nil start end step nil nil nil )))
9814
9923
9815
9924
(neg? step)
9816
9925
(if (>= end start)
9817
9926
()
9818
- (Range. nil start end step nil nil nil ))
9927
+ (if (and (integer? start) (integer? end) (integer? step))
9928
+ (IntegerRange. nil start end step nil nil nil )
9929
+ (Range. nil start end step nil nil nil )))
9819
9930
9820
9931
:else
9821
9932
(if (== end start)
@@ -10429,6 +10540,9 @@ reduces them without incurring seq initialization"
10429
10540
Range
10430
10541
(-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer " (" " " " )" opts coll))
10431
10542
10543
+ IntegerRange
10544
+ (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer " (" " " " )" opts coll))
10545
+
10432
10546
Cycle
10433
10547
(-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer " (" " " " )" opts coll))
10434
10548
0 commit comments