Remove high() and low() procs from queues module

Just in case as they are said not overloadable. No deprecation because this is during a PR: those procs didn't exist before.
Also update comment due to failed optimization attempt using copyMem() for POD datatypes.
This commit is contained in:
ReneSac 2016-06-16 18:08:15 -03:00
commit 67c7a925c1

View file

@ -63,15 +63,6 @@ proc len*[T](q: Queue[T]): int {.inline.}=
## Return the number of elements of `q`. ## Return the number of elements of `q`.
result = q.count result = q.count
proc low*[T](q: Queue[T]): int {.inline.}=
## Return the index of the oldest element of `q` (always 0).
result = 0
proc high*[T](q: Queue[T]): int {.inline.}=
## Return the index of the last element inserted on `q` (equivalent to
## `q.len - 1`).
result = q.count - 1
template emptyCheck(q) = template emptyCheck(q) =
# Bounds check for the regular queue access. # Bounds check for the regular queue access.
when compileOption("boundChecks"): when compileOption("boundChecks"):
@ -151,8 +142,8 @@ proc add*[T](q: var Queue[T], item: T) =
var cap = q.mask+1 var cap = q.mask+1
if unlikely(q.count >= cap): if unlikely(q.count >= cap):
var n = newSeq[T](cap*2) var n = newSeq[T](cap*2)
for i, x in q: for i, x in q: # don't use copyMem because the GC and because it's slower.
shallowCopy(n[i], x) # does not use copyMem because the GC. shallowCopy(n[i], x)
shallowCopy(q.data, n) shallowCopy(q.data, n)
q.mask = cap*2 - 1 q.mask = cap*2 - 1
q.wr = q.count q.wr = q.count
@ -203,8 +194,6 @@ when isMainModule:
assert q[^1] == q.back and q.back == 789 assert q[^1] == q.back and q.back == 789
q[0] = 42 q[0] = 42
q[^1] = 7 q[^1] = 7
assert q[q.low] == 42
assert q[q.high] == 7
assert 6 in q and 789 notin q assert 6 in q and 789 notin q
assert q.find(6) >= 0 assert q.find(6) >= 0