PersistentVector.fromArray

functionsince v0.0-1006Edit
(PersistentVector.fromArray xs no-clone)

Source code @ clojurescript:src/main/cljs/cljs/core.cljs
(set! (.-fromArray PersistentVector)
  (fn [xs ^boolean no-clone]
    (let [l (alength xs)
          xs (if no-clone xs (aclone xs))]
      (if (< l 32)
        (PersistentVector. nil l 5 (.-EMPTY-NODE PersistentVector) xs nil)
        (let [node (.slice xs 0 32)
              v (PersistentVector. nil 32 5 (.-EMPTY-NODE PersistentVector) node nil)]
          (loop [i 32 out (-as-transient v)]
            (if (< i l)
              (recur (inc i) (conj! out (aget xs i)))
              (persistent! out))))))))