Skip to content

Commit

Permalink
move toDeque to after addLast (#19233) [backport:1.0]
Browse files Browse the repository at this point in the history
Changes the order of procs definitions in order to avoid calling an undefined proc.

(cherry picked from commit c989542)
  • Loading branch information
MichalMarsalek authored and narimiran committed Dec 10, 2021
1 parent ac57c31 commit 83c472c
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lib/pure/collections/deques.nim
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,6 @@ proc initDeque*[T](initialSize: int = defaultInitialSize): Deque[T] =
## * `toDeque proc <#toDeque,openArray[T]>`_
result.initImpl(initialSize)

proc toDeque*[T](x: openArray[T]): Deque[T] {.since: (1, 3).} =
## Creates a new deque that contains the elements of `x` (in the same order).
##
## **See also:**
## * `initDeque proc <#initDeque,int>`_
runnableExamples:
let a = toDeque([7, 8, 9])
assert len(a) == 3
assert $a == "[7, 8, 9]"

result.initImpl(x.len)
for item in items(x):
result.addLast(item)

proc len*[T](deq: Deque[T]): int {.inline.} =
## Returns the number of elements of `deq`.
result = deq.count
Expand Down Expand Up @@ -303,6 +289,20 @@ proc addLast*[T](deq: var Deque[T], item: sink T) =
deq.data[deq.tail] = item
deq.tail = (deq.tail + 1) and deq.mask

proc toDeque*[T](x: openArray[T]): Deque[T] {.since: (1, 3).} =
## Creates a new deque that contains the elements of `x` (in the same order).
##
## **See also:**
## * `initDeque proc <#initDeque,int>`_
runnableExamples:
let a = toDeque([7, 8, 9])
assert len(a) == 3
assert $a == "[7, 8, 9]"

result.initImpl(x.len)
for item in items(x):
result.addLast(item)

proc peekFirst*[T](deq: Deque[T]): lent T {.inline.} =
## Returns the first element of `deq`, but does not remove it from the deque.
##
Expand Down

0 comments on commit 83c472c

Please sign in to comment.