File tree Expand file tree Collapse file tree 1 file changed +14
-17
lines changed
Expand file tree Collapse file tree 1 file changed +14
-17
lines changed Original file line number Diff line number Diff line change 3131 last: ptr Chunk [T]
3232 lastCap: int
3333
34+ proc `=destroy` * [T](p: var Pool [T]) =
35+ var it = p.last
36+ while it != nil :
37+ when not supportsCopyMem (T):
38+ for i in 0 ..< it.len:
39+ `=destroy` (it.elems[i])
40+ let next = it.next
41+ deallocShared (it)
42+ it = next
43+
44+ proc `=copy` * [T](dest: var Pool [T]; src: Pool [T]) {.error .}
45+
3446proc newNode * [T](p: var Pool [T]): ptr T =
3547 if p.len >= p.lastCap:
3648 if p.lastCap == 0 : p.lastCap = 4
3749 elif p.lastCap < 65_000 : p.lastCap *= 2
3850 when not supportsCopyMem (T):
39- var n = cast [ptr Chunk [T]](allocShared0 (sizeof (Chunk [T]) + p.lastCap * sizeof (T)))
51+ let n = cast [ptr Chunk [T]](allocShared0 (sizeof (Chunk [T]) + p.lastCap * sizeof (T)))
4052 else :
41- var n = cast [ptr Chunk [T]](allocShared (sizeof (Chunk [T]) + p.lastCap * sizeof (T)))
53+ let n = cast [ptr Chunk [T]](allocShared (sizeof (Chunk [T]) + p.lastCap * sizeof (T)))
4254 n.next = nil
4355 n.next = p.last
4456 p.last = n
@@ -47,21 +59,6 @@ proc newNode*[T](p: var Pool[T]): ptr T =
4759 inc p.len
4860 inc p.last.len
4961
50- proc `=` [T](dest: var Pool [T]; src: Pool [T]) {.error .}
51-
52- proc `=destroy` [T](p: var Pool [T]) =
53- var it = p.last
54- while it != nil :
55- when not supportsCopyMem (T):
56- for i in 0 ..< it.len:
57- `=destroy` (it.elems[i])
58- let next = it.next
59- deallocShared (it)
60- it = next
61- p.len = 0
62- p.lastCap = 0
63- p.last = nil
64-
6562when isMainModule :
6663 const withNonTrivialDestructor = false
6764 include prelude
You can’t perform that action at this time.
0 commit comments