aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2024-06-14 20:27:03 +0200
committerGitHub <noreply@github.com>2024-06-14 20:27:03 +0200
commitfa4fbbe1cebfca621cb687f3bc2d40691c1ae0d0 (patch)
treea2d1df0fde94c13aea7badff1a87e2ddbf02d842
parentb19bf5bbda05f5629d1b1435521e9fd9402e0506 (diff)
parent759139089fc38c59882a29bce7dee031fa6385b3 (diff)
Merge pull request #3758 from jones-josh/master
Fix big.shrink not actually shrinking
-rw-r--r--core/math/big/internal.odin9
1 files changed, 7 insertions, 2 deletions
diff --git a/core/math/big/internal.odin b/core/math/big/internal.odin
index fa747e46a..360d063e9 100644
--- a/core/math/big/internal.odin
+++ b/core/math/big/internal.odin
@@ -2178,15 +2178,20 @@ internal_int_grow :: proc(a: ^Int, digits: int, allow_shrink := false, allocator
}
/*
- If not yet iniialized, initialize the `digit` backing with the allocator we were passed.
+ If not yet initialized, initialize the `digit` backing with the allocator we were passed.
*/
if cap == 0 {
a.digit = make([dynamic]DIGIT, needed, allocator)
- } else if cap != needed {
+ } else if cap < needed {
/*
`[dynamic]DIGIT` already knows what allocator was used for it, so resize will do the right thing.
*/
resize(&a.digit, needed)
+ } else if cap > needed && allow_shrink {
+ /*
+ Same applies to builtin.shrink here as resize above
+ */
+ builtin.shrink(&a.digit, needed)
}
/*
Let's see if the allocation/resize worked as expected.