aboutsummaryrefslogtreecommitdiff
path: root/lib/std/deque.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-09-21 04:55:39 -0700
committerGitHub <noreply@github.com>2025-09-21 04:55:39 -0700
commit594cb38fcb6c2edccee6b2fd74adec81b3be547a (patch)
treec8a29f062fac286cfef622737affaaadc4ff4d73 /lib/std/deque.zig
parent010d9a63f20d8a4bd14cff0ada690b2d127a0371 (diff)
parent3cc0fc601af62adebf6b9f3bb1a241fa8a501d0b (diff)
downloadzig-594cb38fcb6c2edccee6b2fd74adec81b3be547a.tar.gz
zig-594cb38fcb6c2edccee6b2fd74adec81b3be547a.zip
Merge pull request #25302 from ziglang/growCapacity
std: remove loop from growCapacity
Diffstat (limited to 'lib/std/deque.zig')
-rw-r--r--lib/std/deque.zig14
1 files changed, 1 insertions, 13 deletions
diff --git a/lib/std/deque.zig b/lib/std/deque.zig
index 7130cd33fe..267b8a0afe 100644
--- a/lib/std/deque.zig
+++ b/lib/std/deque.zig
@@ -56,7 +56,7 @@ pub fn Deque(comptime T: type) type {
/// Invalidates element pointers if additional memory is needed.
pub fn ensureTotalCapacity(deque: *Self, gpa: Allocator, new_capacity: usize) Allocator.Error!void {
if (deque.buffer.len >= new_capacity) return;
- return deque.ensureTotalCapacityPrecise(gpa, growCapacity(deque.buffer.len, new_capacity));
+ return deque.ensureTotalCapacityPrecise(gpa, std.ArrayList(T).growCapacity(new_capacity));
}
/// If the current capacity is less than `new_capacity`, this function will
@@ -243,18 +243,6 @@ pub fn Deque(comptime T: type) type {
return index - head_len;
}
}
-
- const init_capacity: comptime_int = @max(1, std.atomic.cache_line / @sizeOf(T));
-
- /// Called when memory growth is necessary. Returns a capacity larger than
- /// minimum that grows super-linearly.
- fn growCapacity(current: usize, minimum: usize) usize {
- var new = current;
- while (true) {
- new +|= new / 2 + init_capacity;
- if (new >= minimum) return new;
- }
- }
};
}