Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* src/cljs/cljs/core.cljs: attempting to optimize seq on vectors

  • Loading branch information...
commit ddd7fa3d960b0fe32083d3cb35ff064e968d53c4 1 parent a0bb601
David Nolen authored
Showing with 20 additions and 7 deletions.
  1. +20 −7 src/cljs/cljs/core.cljs
View
27 src/cljs/cljs/core.cljs
@@ -2481,6 +2481,25 @@ reduces them without incurring seq initialization"
(declare tv-editable-root tv-editable-tail TransientVector deref)
+(defn vector-seq [v offset]
+ (let [c (-count v)]
+ (when (pos? c)
+ (reify
+ IPrintable
+ (-pr-seq [vseq opts] (pr-sequential pr-seq "(" " " ")" opts vseq))
+ ISequential
+ IEquiv
+ (-equiv [vseq other] (equiv-sequential vseq other))
+ ISeq
+ (-first [_] (-nth v offset))
+ (-rest [_]
+ (let [offset (inc offset)]
+ (if (< offset c)
+ (vector-seq v offset)
+ ())))
+ ISeqable
+ (-seq [vseq] vseq)))))
+
(deftype PersistentVector [meta cnt shift root tail ^:mutable __hash]
Object
(toString [this]
@@ -2538,13 +2557,7 @@ reduces them without incurring seq initialization"
ISeqable
(-seq [coll]
- (when (pos? cnt)
- (let [vector-seq
- (fn vector-seq [i]
- (lazy-seq
- (when (< i cnt)
- (cons (-nth coll i) (vector-seq (inc i))))))]
- (vector-seq 0))))
+ (vector-seq coll 0))
ICounted
(-count [coll] cnt)
Please sign in to comment.
Something went wrong with that request. Please try again.