@@ -9650,7 +9650,7 @@ reduces them without incurring seq initialization"
96509650 (take-while (mk-bound-fn sc start-test start-key)
96519651 (if ((mk-bound-fn sc end-test end-key) e) s (next s))))))
96529652
9653- (deftype RangeChunk [start step count]
9653+ (deftype IntegerRangeChunk [start step count]
96549654 ICounted
96559655 (-count [coll] count)
96569656
@@ -9669,7 +9669,7 @@ reduces them without incurring seq initialization"
96699669 (-drop-first [coll]
96709670 (if (<= count 1 )
96719671 (throw (js/Error. " -drop-first of empty chunk" ))
9672- (RangeChunk . (+ start step) step (dec count)))))
9672+ (IntegerRangeChunk . (+ start step) step (dec count)))))
96739673
96749674(deftype RangeIterator [^:mutable i end step]
96759675 Object
@@ -9682,7 +9682,7 @@ reduces them without incurring seq initialization"
96829682 (set! i (+ i step))
96839683 ret)))
96849684
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]
96869686 Object
96879687 (toString [coll]
96889688 (pr-str* coll))
@@ -9701,18 +9701,18 @@ reduces them without incurring seq initialization"
97019701 (let [count (-count coll)]
97029702 (if (> count 32 )
97039703 (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))))))
97079707
97089708 ICloneable
9709- (-clone [_] (Range . meta start end step chunk chunk-next __hash))
9709+ (-clone [_] (IntegerRange . meta start end step chunk chunk-next __hash))
97109710
97119711 IWithMeta
97129712 (-with-meta [rng new-meta]
97139713 (if (identical? new-meta meta)
97149714 rng
9715- (Range . new-meta start end step chunk chunk-next __hash)))
9715+ (IntegerRange . new-meta start end step chunk chunk-next __hash)))
97169716
97179717 IMeta
97189718 (-meta [rng] meta)
@@ -9736,9 +9736,9 @@ reduces them without incurring seq initialization"
97369736 (-next [rng]
97379737 (if (pos? step)
97389738 (when (< (+ start step) end)
9739- (Range . nil (+ start step) end step nil nil nil ))
9739+ (IntegerRange . nil (+ start step) end step nil nil nil ))
97409740 (when (> (+ start step) end)
9741- (Range . nil (+ start step) end step nil nil nil ))))
9741+ (IntegerRange . nil (+ start step) end step nil nil nil ))))
97429742
97439743 IChunkedSeq
97449744 (-chunked-first [rng]
@@ -9796,6 +9796,113 @@ reduces them without incurring seq initialization"
97969796 (recur (+ i step) ret)))
97979797 ret))))
97989798
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+
97999906(es6-iterable Range)
98009907
98019908(defn range
@@ -9810,12 +9917,16 @@ reduces them without incurring seq initialization"
98109917 (pos? step)
98119918 (if (<= end start)
98129919 ()
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 )))
98149923
98159924 (neg? step)
98169925 (if (>= end start)
98179926 ()
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 )))
98199930
98209931 :else
98219932 (if (== end start)
@@ -10429,6 +10540,9 @@ reduces them without incurring seq initialization"
1042910540 Range
1043010541 (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer " (" " " " )" opts coll))
1043110542
10543+ IntegerRange
10544+ (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer " (" " " " )" opts coll))
10545+
1043210546 Cycle
1043310547 (-pr-writer [coll writer opts] (pr-sequential-writer writer pr-writer " (" " " " )" opts coll))
1043410548
0 commit comments