Permalink
Browse files

Eliminate some reflective calls

  • Loading branch information...
1 parent 21554bf commit 1c53a172a830f4dadbd7c326c3dccdd160f81f0f @duelinmarkers duelinmarkers committed with cemerick Jun 10, 2013
@@ -131,7 +131,7 @@
; oh, kill me now
(defn- markdown-escape
- [s]
+ [^String s]
(.replaceAll s "([*_])" "\\\\$1"))
(defn- message-slot-markdown
@@ -8,7 +8,7 @@
(:import clojure.lang.LineNumberingPushbackReader
(java.io StringReader Writer)
java.util.concurrent.atomic.AtomicLong
- (java.util.concurrent Executor LinkedBlockingQueue ThreadFactory
+ (java.util.concurrent Executor BlockingQueue LinkedBlockingQueue ThreadFactory
SynchronousQueue TimeUnit ThreadPoolExecutor)))
(def ^{:dynamic true
@@ -50,7 +50,7 @@
:read (if (string? code)
(let [reader (LineNumberingPushbackReader. (StringReader. code))]
#(read reader false %2))
- (let [^java.util.Iterator code (.iterator code)]
+ (let [code (.iterator ^Iterable code)]
#(or (and (.hasNext code) (.next code)) %2)))
:prompt (fn [])
:need-prompt (constantly false)
@@ -104,12 +104,13 @@
[& {:keys [keep-alive queue thread-factory]
:or {keep-alive 30000
queue (SynchronousQueue.)}}]
- ; ThreadPoolExecutor in JDK5 *will not run* submitted jobs if the core pool size is zero and
- ; the queue has not yet rejected a job (see http://kirkwylie.blogspot.com/2008/10/java5-vs-java6-threadpoolexecutor.html)
- (ThreadPoolExecutor. (if jdk6? 0 1) Integer/MAX_VALUE
- (long 30000) TimeUnit/MILLISECONDS
- queue
- (or thread-factory (configure-thread-factory))))
+ (let [^ThreadFactory thread-factory (or thread-factory (configure-thread-factory))]
+ ; ThreadPoolExecutor in JDK5 *will not run* submitted jobs if the core pool size is zero and
+ ; the queue has not yet rejected a job (see http://kirkwylie.blogspot.com/2008/10/java5-vs-java6-threadpoolexecutor.html)
+ (ThreadPoolExecutor. (if jdk6? 0 1) Integer/MAX_VALUE
+ (long 30000) TimeUnit/MILLISECONDS
+ ^BlockingQueue queue
+ thread-factory)))
; A little mini-agent implementation. Needed because agents cannot be used to host REPL
; evaluation: http://dev.clojure.org/jira/browse/NREPL-17
@@ -38,7 +38,7 @@
(number? x) (.append buf (char x))
(not off) (.append buf x)
; the CharSequence overload of append takes an *end* idx, not length!
- (instance? CharSequence x) (.append buf ^CharSequence x off (+ len off))
+ (instance? CharSequence x) (.append buf ^CharSequence x (int off) (int (+ len off)))
:else (.append buf ^chars x off len))
(when (<= *out-limit* (.length buf))
(.flush ^Writer this))))
@@ -225,7 +225,7 @@
(clojure.main/skip-if-eol in))
(h msg))
(= op "stdin")
- (let [q (-> (meta session) ^Writer (:input-queue))]
+ (let [q (-> (meta session) ^LinkedBlockingQueue (:input-queue))]
(locking q
(doseq [c stdin] (.put q c)))
(t/send transport (response-for msg :status :done)))
@@ -10,7 +10,7 @@
session
load-file))
(:use [clojure.tools.nrepl.misc :only (returning response-for log)])
- (:import (java.net Socket ServerSocket InetSocketAddress)))
+ (:import (java.net Socket ServerSocket InetSocketAddress InetAddress)))
(defn handle*
[msg handler transport]
@@ -27,6 +27,13 @@
(future (handle* msg handler transport))
(recur handler transport)))
+(defn- safe-close
+ [^java.io.Closeable x]
+ (try
+ (.close x)
+ (catch java.io.IOException e
+ (log e "Failed to close " x))))
+
(defn- accept-connection
[{:keys [^ServerSocket server-socket open-transports transport greeting handler]
:as server}]
@@ -39,16 +46,9 @@
(handle handler transport)
(finally
(swap! open-transports disj transport)
- (.close transport)))))
+ (safe-close transport)))))
(future (accept-connection server)))))
-(defn- safe-close
- [^java.io.Closeable x]
- (try
- (.close x)
- (catch java.io.IOException e
- (log e "Failed to close " x))))
-
(defn stop-server
"Stops a server started via `start-server`."
[{:keys [open-transports ^ServerSocket server-socket] :as server}]

0 comments on commit 1c53a17

Please sign in to comment.