diff options
author | Clyybber <darkmine956@gmail.com> | 2021-03-15 13:03:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-15 13:03:00 +0100 |
commit | 283d9abc84a9a71b88bb34b66f15157b1307e11c (patch) | |
tree | fb56b5496ca0141a61ef1eb623cf1b18730e6eb9 /doc/destructors.rst | |
parent | 5c49480d8c12b771ab10a296b6dce66ea05401f4 (diff) | |
download | Nim-283d9abc84a9a71b88bb34b66f15157b1307e11c.tar.gz |
Make add work in the destructors example (#17354)
Diffstat (limited to 'doc/destructors.rst')
-rw-r--r-- | doc/destructors.rst | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/doc/destructors.rst b/doc/destructors.rst index 98926435f..4f06de455 100644 --- a/doc/destructors.rst +++ b/doc/destructors.rst @@ -62,7 +62,9 @@ written as: a.data = b.data proc add*[T](x: var myseq[T]; y: sink T) = - if x.len >= x.cap: resize(x) + if x.len >= x.cap: + x.cap = max(x.len + 1, x.cap * 2) + x.data = cast[typeof(x.data)](realloc(x.data, x.cap * sizeof(T))) x.data[x.len] = y inc x.len |