Skip to content

Commit 947153f

Browse files
committed
Use primitive-math
1 parent 0cf085d commit 947153f

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

project.clj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:dependencies [[org.clojure/clojure "1.11.1" :scope "provided"]
88
[org.clojure/tools.logging "1.2.4" :exclusions [org.clojure/clojure]]
99
[org.clj-commons/dirigiste "1.0.3"]
10+
[org.clj-commons/primitive-math "1.0.0"]
1011
[riddley "0.2.0"]
1112
[org.clojure/core.async "1.6.673" :scope "provided"]
1213
[potemkin "0.4.6"]]

src/manifold/executor.clj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(ns manifold.executor
22
(:require
3-
[clojure.tools.logging :as log])
3+
[clojure.tools.logging :as log]
4+
[clj-commons.primitive-math :as p])
45
(:import
56
[io.aleph.dirigiste
67
Executors
@@ -147,7 +148,7 @@
147148
(Executor.
148149
thread-factory
149150
(if (and queue-length (pos? queue-length))
150-
(if (<= queue-length 1024)
151+
(if (p/<= queue-length 1024)
151152
(ArrayBlockingQueue. queue-length false)
152153
(LinkedBlockingQueue. (int queue-length)))
153154
(SynchronousQueue. false))
@@ -177,9 +178,9 @@
177178
:max-threads num-threads
178179
:controller (reify Executor$Controller
179180
(shouldIncrement [_ n]
180-
(< n num-threads))
181+
(p/< n num-threads))
181182
(adjustment [_ s]
182-
(- num-threads (.getNumWorkers s)))))))))
183+
(p/- num-threads (.getNumWorkers s)))))))))
183184

184185
(defn utilization-executor
185186
"Returns an executor which sizes the thread pool according to target utilization, within

src/manifold/time.clj

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
[manifold.executor :as ex]
77
[clojure.string :as str]
88
[manifold.utils :refer [definterface+]]
9-
[potemkin.types :refer [defprotocol+]])
9+
[potemkin.types :refer [defprotocol+]]
10+
[clj-commons.primitive-math :as p])
1011
(:import
1112
[java.util
1213
Calendar
@@ -23,12 +24,12 @@
2324
(defn nanoseconds
2425
"Converts nanoseconds -> milliseconds"
2526
[^double n]
26-
(/ n 1e6))
27+
(p// n 1e6))
2728

2829
(defn microseconds
2930
"Converts microseconds -> milliseconds"
3031
[^double n]
31-
(/ n 1e3))
32+
(p// n 1e3))
3233

3334
(defn milliseconds
3435
"Converts milliseconds -> milliseconds"
@@ -38,27 +39,27 @@
3839
(defn seconds
3940
"Converts seconds -> milliseconds"
4041
[^double n]
41-
(* n 1e3))
42+
(p/* n 1e3))
4243

4344
(defn minutes
4445
"Converts minutes -> milliseconds"
4546
[^double n]
46-
(* n 6e4))
47+
(p/* n 6e4))
4748

4849
(defn hours
4950
"Converts hours -> milliseconds"
5051
[^double n]
51-
(* n 36e5))
52+
(p/* n 36e5))
5253

5354
(defn days
5455
"Converts days -> milliseconds"
5556
[^double n]
56-
(* n 864e5))
57+
(p/* n 864e5))
5758

5859
(defn hz
5960
"Converts frequency -> period in milliseconds"
6061
[^double n]
61-
(/ 1e3 n))
62+
(p// 1e3 n))
6263

6364
(let [intervals (partition 2 ["d" (days 1)
6465
"h" (hours 1)
@@ -75,9 +76,9 @@
7576
"0s"
7677
(str/trim s))
7778
(let [[desc ^double val] (first intervals)]
78-
(if (>= n val)
79+
(if (p/>= n val)
7980
(recur
80-
(str s (int (/ n val)) desc " ")
81+
(str s (int (p// n val)) desc " ")
8182
(rem n val)
8283
(rest intervals))
8384
(recur s n (rest intervals))))))))
@@ -161,7 +162,7 @@
161162
(defn scheduled-executor->clock [^ScheduledExecutorService e]
162163
(reify IClock
163164
(in [_ interval-millis f]
164-
(let [^Future scheduled-future (.schedule e f (long (* interval-millis 1e3)) TimeUnit/MICROSECONDS)
165+
(let [^Future scheduled-future (.schedule e f (long (p/* interval-millis 1e3)) TimeUnit/MICROSECONDS)
165166
cancel-fn (fn []
166167
(.cancel scheduled-future false))]
167168
cancel-fn))
@@ -173,8 +174,8 @@
173174
(deliver future-ref
174175
(.scheduleAtFixedRate e
175176
^Runnable (cancel-on-exception f cancel-fn)
176-
(long (* delay-millis 1e3))
177-
(long (* period-millis 1e3))
177+
(long (p/* delay-millis 1e3))
178+
(long (p/* period-millis 1e3))
178179
TimeUnit/MICROSECONDS))
179180
cancel-fn))))
180181

@@ -190,14 +191,14 @@
190191
(reify
191192
IClock
192193
(in [this interval-millis f]
193-
(swap! events update-in [(+ ^double @now interval-millis)] #(conj (or % []) f))
194+
(swap! events update-in [(p/+ ^double @now interval-millis)] #(conj (or % []) f))
194195
(advance this 0))
195196
(every [this delay-millis period-millis f]
196-
(assert (< 0 period-millis))
197+
(assert (p/< 0.0 period-millis))
197198
(let [period (atom period-millis)
198199
cancel-fn #(reset! period -1)]
199200
(->> (with-meta (cancel-on-exception f cancel-fn) {::period period})
200-
(.in this (max 0 delay-millis)))
201+
(.in this (p/max 0.0 delay-millis)))
201202
cancel-fn))
202203

203204
IMockClock
@@ -207,7 +208,7 @@
207208
(let [limit (+ ^double @now ^double time)]
208209
(loop []
209210
(if (or (empty? @events)
210-
(< limit ^double (key (first @events))))
211+
(p/< limit ^double (key (first @events))))
211212
(do
212213
(reset! now limit)
213214
nil)
@@ -217,7 +218,7 @@
217218
(reset! now t)
218219
(doseq [f fs]
219220
(let [period (some-> f meta ::period deref)]
220-
(when (or (nil? period) (pos? ^double period))
221+
(when (or (nil? period) (p/< 0.0 ^double period))
221222
(try
222223
(f)
223224
(when period (.in this period f))
@@ -281,5 +282,5 @@
281282
"Schedules no-arg function `f` to be invoked at `timestamp`, which is the milliseconds
282283
since the epoch. Returns a deferred representing the returned value of the function
283284
(unwrapped if `f` itself returns a deferred)."
284-
[^double timestamp f]
285-
(in (max 0 (- timestamp (System/currentTimeMillis))) f))
285+
[^long timestamp f]
286+
(in (p/max 0 (p/- timestamp (System/currentTimeMillis))) f))

0 commit comments

Comments
 (0)