diff options
author | Rich Hickey <richhickey@gmail.com> | 2010-04-06 11:39:00 -0400 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2010-04-06 11:39:00 -0400 |
commit | f81e612cc9ff91ddefc1d86e270cd7f018701802 (patch) | |
tree | b34ed0b2e50cda3005d16fb108f6a496eb59b16a /src/clj | |
parent | 68322a4c604693e8b51802abba70861a87adfaf0 (diff) |
perf tweaks nth, count, get
Diffstat (limited to 'src/clj')
-rw-r--r-- | src/clj/clojure/core.clj | 4 | ||||
-rw-r--r-- | src/clj/clojure/gvec.clj | 7 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 1508a76c..a728bc0d 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -651,6 +651,8 @@ (defn count "Returns the number of items in the collection. (count nil) returns 0. Also works on strings, arrays, and Java Collections and Maps" + {:tag Integer + :inline (fn [x] `(. clojure.lang.RT (count ~x)))} [coll] (clojure.lang.RT/count coll)) (defn int @@ -1023,6 +1025,8 @@ (defn get "Returns the value mapped to key, not-found or nil if key not present." + {:inline (fn [m k & nf] `(. clojure.lang.RT (get ~m ~k ~@nf))) + :inline-arities #{2 3}} ([map key] (. clojure.lang.RT (get map key))) ([map key not-found] diff --git a/src/clj/clojure/gvec.clj b/src/clj/clojure/gvec.clj index dc1f0e79..f00de920 100644 --- a/src/clj/clojure/gvec.clj +++ b/src/clj/clojure/gvec.clj @@ -114,6 +114,11 @@ (nth [this i] (let [a (.arrayFor this i)] (.aget am a (bit-and i (int 0x1f))))) + (nth [this i not-found] + (let [z (int 0)] + (if (and (>= i z) (< i (.count this))) + (.nth this i) + not-found))) clojure.lang.IPersistentCollection (cons [this val] @@ -222,7 +227,7 @@ clojure.core.IVecImpl (tailoff [_] - (- cnt (alength tail))) + (- cnt (.alength am tail))) (arrayFor [this i] (if (and (<= (int 0) i) (< i cnt)) |