diff options
author | 2023-06-10 15:38:09 -0700 | |
---|---|---|
committer | 2023-06-10 15:38:09 -0700 | |
commit | 02eafd5019150357012ebb7a39f1c264ba73599e (patch) | |
tree | 1db72d24320147dc0660534576c33ac7f27dc457 /src/string_mutable.zig | |
parent | 04cd6a82b880b38c9fe17501f306c5f116e219ce (diff) | |
download | bun-02eafd5019150357012ebb7a39f1c264ba73599e.tar.gz bun-02eafd5019150357012ebb7a39f1c264ba73599e.tar.zst bun-02eafd5019150357012ebb7a39f1c264ba73599e.zip |
Make cold `bun install` use 2x less memory (#3271)
* Make cold `bun install` use 2x less memory
In this benchmark: https://github.com/orogene/orogene/blob/main/BENCHMARKS.md
This brings us from around 2.7 GB to 1.2 GB of memory
* Address comments
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to '')
-rw-r--r-- | src/string_mutable.zig | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/string_mutable.zig b/src/string_mutable.zig index e6738ae7f..cb8e1633e 100644 --- a/src/string_mutable.zig +++ b/src/string_mutable.zig @@ -235,6 +235,13 @@ pub const MutableString = struct { return self.list.items; } + /// Clear the existing value without freeing the memory or shrinking the capacity. + pub fn move(self: *MutableString) []u8 { + const out = self.list.items; + self.list = .{}; + return out; + } + pub fn toOwnedSentinelLeaky(self: *MutableString) [:0]u8 { if (self.list.items.len > 0 and self.list.items[self.list.items.len - 1] != 0) { self.list.append( |