Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use unchecked arithmetic

  • Loading branch information...
commit f62cfe5340db5c81788f5ed4e55a2097331dc246 1 parent 5a22f90
@amalloy authored
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/ring_buffer/core.clj
View
8 src/ring_buffer/core.clj
@@ -2,6 +2,12 @@
(:import (clojure.lang Counted Sequential IPersistentCollection IPersistentStack Reversible IObj)
(java.io 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]
Counted
(count [this] len)
@@ -55,3 +61,5 @@
"Create an empty ring buffer with the specified [capacity]."
[capacity]
(RingBuffer. 0 0 (vec (repeat capacity nil)) nil))
+
+(set! *unchecked-math* old-unchecked-math)
Please sign in to comment.
Something went wrong with that request. Please try again.