Skip to content

Commit

Permalink
Don't compute io/resource twice for :path
Browse files Browse the repository at this point in the history
  • Loading branch information
vemv authored and bbatsov committed Nov 11, 2021
1 parent 3e448d5 commit 646af3e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
19 changes: 10 additions & 9 deletions src-jdk8/orchard/java/legacy_parser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,14 @@
(try
(let [path (source-path klass)]
(when-let [root (parse-java path)]
(assoc (->> (map parse-info (.classes root))
(filter #(= klass (:class %)))
(first))
;; relative path on the classpath
:file path
;; Legacy key. Please do not remove - we don't do breaking changes!
:path (-> path io/resource .getPath)
;; Full URL, e.g. file:.. or jar:...
:resource-url (io/resource path))))
(let [path-resource (io/resource path)]
(assoc (->> (map parse-info (.classes root))
(filter #(= klass (:class %)))
(first))
;; relative path on the classpath
:file path
;; Legacy key. Please do not remove - we don't do breaking changes!
:path (.getPath path-resource)
;; Full URL, e.g. file:.. or jar:...
:resource-url path-resource))))
(catch Abort _)))
29 changes: 15 additions & 14 deletions src-newer-jdks/orchard/java/parser.clj
Original file line number Diff line number Diff line change
Expand Up @@ -296,19 +296,20 @@
(when-let [path (source-path klass)]
(when-let [^DocletEnvironment root (parse-java path (module-name klass))]
(try
(assoc (->> (.getIncludedElements root)
(filter #(#{ElementKind/CLASS
ElementKind/INTERFACE
ElementKind/ENUM}
(.getKind ^Element %)))
(map #(parse-info % root))
(filter #(= klass (:class %)))
(first))
;; relative path on the classpath
:file path
;; Legacy key. Please do not remove - we don't do breaking changes!
:path (-> path io/resource .getPath)
;; Full URL, e.g. file:.. or jar:...
:resource-url (io/resource path))
(let [path-resource (io/resource path)]
(assoc (->> (.getIncludedElements root)
(filter #(#{ElementKind/CLASS
ElementKind/INTERFACE
ElementKind/ENUM}
(.getKind ^Element %)))
(map #(parse-info % root))
(filter #(= klass (:class %)))
(first))
;; relative path on the classpath
:file path
;; Legacy key. Please do not remove - we don't do breaking changes!
:path (.getPath path-resource)
;; Full URL, e.g. file:.. or jar:...
:resource-url path-resource))
(finally (.close (.getJavaFileManager root))))))
(catch Throwable _)))

0 comments on commit 646af3e

Please sign in to comment.