diff options
author | Rich Hickey <richhickey@gmail.com> | 2009-08-19 21:11:42 -0400 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2009-08-19 21:11:42 -0400 |
commit | 7ba336f50f32dbe9ce06ef00d1482e67341dbdb6 (patch) | |
tree | a6ada86ef5c05891c001d55409fa4880c4bd7fa4 /src/jvm | |
parent | 2098f5d57ecf3affb09a4cdaf2e01ad4de861eef (diff) |
inline nth with not-found
Diffstat (limited to 'src/jvm')
-rw-r--r-- | src/jvm/clojure/lang/RT.java | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/jvm/clojure/lang/RT.java b/src/jvm/clojure/lang/RT.java index 18be0bf2..a5da74a2 100644 --- a/src/jvm/clojure/lang/RT.java +++ b/src/jvm/clojure/lang/RT.java @@ -756,16 +756,17 @@ static public Object nth(Object coll, int n){ } static public Object nth(Object coll, int n, Object notFound){ - if(coll == null) - return notFound; - else if(n < 0) - return notFound; - else if(coll instanceof IPersistentVector) { - IPersistentVector v = (IPersistentVector) coll; - if(n < v.count()) + if(coll instanceof Indexed) { + Indexed v = (Indexed) coll; + if(n >= 0 && n < v.count()) return v.nth(n); return notFound; } + else if(coll == null) + return notFound; + else if(n < 0) + return notFound; + else if(coll instanceof String) { String s = (String) coll; if(n < s.length()) |