Permalink
Browse files

Cache jars-handler/try-read results

  • Loading branch information...
1 parent f035f94 commit 305174cd7243409b5cd0f1c7de7b78097466dc9f @jstepien committed Oct 1, 2011
Showing with 15 additions and 14 deletions.
  1. +15 −14 src/clodoc/jars_handler.clj
@@ -78,20 +78,21 @@
[sexp]
(definitions (first sexp)))
-(defn try-read
- [^String code]
- (let [lines (string/split-lines code)
- lines-count (count lines)]
- (loop [num 2]
- (if (> num lines-count)
- ['() ""]
- (let [joined (string/join "\n" (take num lines))
- read-str #(with-in-str % (read))
- sexp (try (read-str joined)
- (catch RuntimeException ex nil))]
- (if sexp
- [sexp joined]
- (recur (inc num))))))))
+(def try-read
+ (memoize
+ (fn [^String code]
+ (let [lines (string/split-lines code)
+ lines-count (count lines)]
+ (loop [num 2]
+ (if (> num lines-count)
+ ['() ""]
+ (let [joined (string/join "\n" (take num lines))
+ read-str #(with-in-str % (read))
+ sexp (try (read-str joined)
+ (catch RuntimeException ex nil))]
+ (if sexp
+ [sexp joined]
+ (recur (inc num))))))))))
(defn source-string
[^String whole-code def]

0 comments on commit 305174c

Please sign in to comment.