Skip to content

Commit 83c472c

Browse files
MichalMarsaleknarimiran
authored andcommitted
move toDeque to after addLast (#19233) [backport:1.0]
Changes the order of procs definitions in order to avoid calling an undefined proc. (cherry picked from commit c989542)
1 parent ac57c31 commit 83c472c

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

lib/pure/collections/deques.nim

+14-14
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,6 @@ proc initDeque*[T](initialSize: int = defaultInitialSize): Deque[T] =
8787
## * `toDeque proc <#toDeque,openArray[T]>`_
8888
result.initImpl(initialSize)
8989

90-
proc toDeque*[T](x: openArray[T]): Deque[T] {.since: (1, 3).} =
91-
## Creates a new deque that contains the elements of `x` (in the same order).
92-
##
93-
## **See also:**
94-
## * `initDeque proc <#initDeque,int>`_
95-
runnableExamples:
96-
let a = toDeque([7, 8, 9])
97-
assert len(a) == 3
98-
assert $a == "[7, 8, 9]"
99-
100-
result.initImpl(x.len)
101-
for item in items(x):
102-
result.addLast(item)
103-
10490
proc len*[T](deq: Deque[T]): int {.inline.} =
10591
## Returns the number of elements of `deq`.
10692
result = deq.count
@@ -303,6 +289,20 @@ proc addLast*[T](deq: var Deque[T], item: sink T) =
303289
deq.data[deq.tail] = item
304290
deq.tail = (deq.tail + 1) and deq.mask
305291

292+
proc toDeque*[T](x: openArray[T]): Deque[T] {.since: (1, 3).} =
293+
## Creates a new deque that contains the elements of `x` (in the same order).
294+
##
295+
## **See also:**
296+
## * `initDeque proc <#initDeque,int>`_
297+
runnableExamples:
298+
let a = toDeque([7, 8, 9])
299+
assert len(a) == 3
300+
assert $a == "[7, 8, 9]"
301+
302+
result.initImpl(x.len)
303+
for item in items(x):
304+
result.addLast(item)
305+
306306
proc peekFirst*[T](deq: Deque[T]): lent T {.inline.} =
307307
## Returns the first element of `deq`, but does not remove it from the deque.
308308
##

0 commit comments

Comments
 (0)