diff --git a/README.md b/README.md index 25bafaf..3d3cce6 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,8 @@ queue.clearPop() capabilities - The objects in this module are **all** tracked references! (Unlike the `std/deques` module which implements them as value types and gives `var` variants of each procedure) +- As with the data structure implemented in `std/deques`, all bounds checking is disabled when compiled with + `--checks:off` or `-d:danger`, but queue size checking is not. To disable queue size checking, pass `-d:noQueueSizeCheck` ## Disclaimer diff --git a/src/private/queues/linked.nim b/src/private/queues/linked.nim index 769f565..3268ace 100644 --- a/src/private/queues/linked.nim +++ b/src/private/queues/linked.nim @@ -83,10 +83,11 @@ proc maxSize*[T](self: LinkedDeque[T]): int = proc getNode[T](self: LinkedDeque[T], i: int): DequeNode[T] {.raises: [IndexDefect, ValueError].} = ## Low level method for indexing and getting ## a node object back - if self.high() == -1: - raise newException(IndexDefect, "LinkedDeque is empty") - elif i > self.high() or i < 0: - raise newException(IndexDefect, &"{i} notin 0..{self.high()}") + when defined(boundChecks): + if self.high() == -1: + raise newException(IndexDefect, "LinkedDeque is empty") + elif i > self.high() or i < 0: + raise newException(IndexDefect, &"{i} notin 0..{self.high()}") var pos = 0 if i < self.high() div 2: # If we're taking an element @@ -217,8 +218,9 @@ proc insert*[T](self: LinkedDeque[T], pos: int, val: T) {.raises: [IndexDefect, ## to O(n) the closer the index gets to the middle of ## the deque. This proc raises an IndexDefect if the ## queue's max size is reached - if self.maxSize > 0 and self.size == self.maxSize: - raise newException(IndexDefect, &"LinkedDeque has reached its maximum size ({self.maxSize})") + when not defined(noQueueSizeCheck): + if self.maxSize > 0 and self.size == self.maxSize: + raise newException(IndexDefect, &"LinkedDeque has reached its maximum size ({self.maxSize})") if pos == 0: self.addLeft(val) else: