Browse files

Use unchecked arithmetic

  • Loading branch information...
amalloy committed Jul 23, 2012
1 parent 5a22f90 commit f62cfe5340db5c81788f5ed4e55a2097331dc246
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/ring_buffer/core.clj
@@ -2,6 +2,12 @@
(:import (clojure.lang Counted Sequential IPersistentCollection IPersistentStack Reversible IObj)
( Writer)))
+;; If one of our numbers gets over 2 billion, the user's ring buffer is way too large!
+;; and count is defined to return an int anyway, so we can't make it work regardless.
+;; So we'll just skip that overflow check for a mild speed boost.
+(def ^:private old-unchecked-math *unchecked-math*)
+(set! *unchecked-math* true)
(deftype RingBuffer [^long start ^long len buf meta]
(count [this] len)
@@ -55,3 +61,5 @@
"Create an empty ring buffer with the specified [capacity]."
(RingBuffer. 0 0 (vec (repeat capacity nil)) nil))
+(set! *unchecked-math* old-unchecked-math)

0 comments on commit f62cfe5

Please sign in to comment.