diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2010-10-11 10:11:32 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-10-12 19:45:57 -0400 |
commit | 83fc4fe476b75553a4c2db8bd4f7fdfc02379dce (patch) | |
tree | 20b1ff6615edf2601f517efffec9f19d224ad487 | |
parent | c50f2b86d91ad057bfc34c03c8ffd5d6634e6435 (diff) |
fixes and tests for #276 find-keyword
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r-- | src/clj/clojure/core.clj | 4 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Keyword.java | 6 | ||||
-rw-r--r-- | test/clojure/test_clojure.clj | 1 | ||||
-rw-r--r-- | test/clojure/test_clojure/keywords.clj | 25 |
4 files changed, 34 insertions, 2 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 3f0408af..83297d20 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -559,7 +559,9 @@ exists. This function will not intern a new keyword. If the keyword has not already been interned, it will return nil. Do not use : in the keyword strings, it will be added automatically." - {:tag clojure.lang.Keyword} + {:tag clojure.lang.Keyword + :added "1.3" + :static true} ([name] (cond (keyword? name) name (symbol? name) (clojure.lang.Keyword/find ^clojure.lang.Symbol name) (string? name) (clojure.lang.Keyword/find ^String name))) diff --git a/src/jvm/clojure/lang/Keyword.java b/src/jvm/clojure/lang/Keyword.java index 743a25f1..2017a959 100644 --- a/src/jvm/clojure/lang/Keyword.java +++ b/src/jvm/clojure/lang/Keyword.java @@ -54,7 +54,11 @@ private Keyword(Symbol sym){ } public static Keyword find(Symbol sym){ - return table.get(sym).get(); + SoftReference<Keyword> ref = table.get(sym); + if (ref != null) + return ref.get(); + else + return null; } public static Keyword find(String ns, String name){ diff --git a/test/clojure/test_clojure.clj b/test/clojure/test_clojure.clj index f2b71a3e..fa482d88 100644 --- a/test/clojure/test_clojure.clj +++ b/test/clojure/test_clojure.clj @@ -63,6 +63,7 @@ :java.shell :transients :def + :keywords ]) (def test-namespaces diff --git a/test/clojure/test_clojure/keywords.clj b/test/clojure/test_clojure/keywords.clj new file mode 100644 index 00000000..9ef86d7d --- /dev/null +++ b/test/clojure/test_clojure/keywords.clj @@ -0,0 +1,25 @@ +; Copyright (c) Rich Hickey. All rights reserved. +; The use and distribution terms for this software are covered by the +; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +; which can be found in the file epl-v10.html at the root of this distribution. +; By using this software in any fashion, you are agreeing to be bound by +; the terms of this license. +; You must not remove this notice, or any other, from this software. + +(ns clojure.test-clojure.keywords + (:use clojure.test)) + +(let [this-ns (str (.name *ns*))] + (deftest test-find-keyword + :foo + ::foo + (let [absent-keyword-sym (gensym "absent-keyword-sym")] + (are [result lookup] (= result (find-keyword lookup)) + :foo :foo + :foo 'foo + :foo "foo" + nil absent-keyword-sym + nil (str absent-keyword-sym)) + (are [result lookup] (= result (find-keyword this-ns lookup)) + ::foo "foo" + nil (str absent-keyword-sym))))) |