mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 19:08:50 +00:00
Make BoundedArray more compact, shrink Data in sql from 32 bytes to 24 bytes (#22210)
### What does this PR do? - Instead of storing `len` in `BoundedArray` as a `usize`, store it as either a `u8` or ` u16` depending on the `buffer_capacity` - Copy-paste `BoundedArray` from the standard library into Bun's codebase as it was removed in https://github.com/ziglang/zig/pull/24699/files#diff-cbd8cbbc17583cb9ea5cc0f711ce0ad447b446e62ea5ddbe29274696dce89e4f and we will probably continue using it ### How did you verify your code works? Ran `bun run zig:check` --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: taylor.fish <contact@taylor.fish>
This commit is contained in:
@@ -1546,11 +1546,11 @@ const LineRange = struct {
|
||||
start: u32,
|
||||
end: u32,
|
||||
};
|
||||
pub fn indexOfLineRanges(text: []const u8, target_line: u32, comptime line_range_count: usize) std.BoundedArray(LineRange, line_range_count) {
|
||||
pub fn indexOfLineRanges(text: []const u8, target_line: u32, comptime line_range_count: usize) bun.BoundedArray(LineRange, line_range_count) {
|
||||
const remaining = text;
|
||||
if (remaining.len == 0) return .{};
|
||||
|
||||
var ranges = std.BoundedArray(LineRange, line_range_count){};
|
||||
var ranges = bun.BoundedArray(LineRange, line_range_count){};
|
||||
|
||||
var current_line: u32 = 0;
|
||||
const first_newline_or_nonascii_i = strings.indexOfNewlineOrNonASCIICheckStart(text, 0, true) orelse {
|
||||
@@ -1644,7 +1644,7 @@ pub fn indexOfLineRanges(text: []const u8, target_line: u32, comptime line_range
|
||||
};
|
||||
|
||||
if (ranges.len == line_range_count and current_line <= target_line) {
|
||||
var new_ranges = std.BoundedArray(LineRange, line_range_count){};
|
||||
var new_ranges = bun.BoundedArray(LineRange, line_range_count){};
|
||||
new_ranges.appendSliceAssumeCapacity(ranges.slice()[1..]);
|
||||
ranges = new_ranges;
|
||||
}
|
||||
@@ -1658,7 +1658,7 @@ pub fn indexOfLineRanges(text: []const u8, target_line: u32, comptime line_range
|
||||
}
|
||||
|
||||
if (ranges.len == line_range_count and current_line <= target_line) {
|
||||
var new_ranges = std.BoundedArray(LineRange, line_range_count){};
|
||||
var new_ranges = bun.BoundedArray(LineRange, line_range_count){};
|
||||
new_ranges.appendSliceAssumeCapacity(ranges.slice()[1..]);
|
||||
ranges = new_ranges;
|
||||
}
|
||||
@@ -1667,10 +1667,10 @@ pub fn indexOfLineRanges(text: []const u8, target_line: u32, comptime line_range
|
||||
}
|
||||
|
||||
/// Get N lines from the start of the text
|
||||
pub fn getLinesInText(text: []const u8, line: u32, comptime line_range_count: usize) ?std.BoundedArray([]const u8, line_range_count) {
|
||||
pub fn getLinesInText(text: []const u8, line: u32, comptime line_range_count: usize) ?bun.BoundedArray([]const u8, line_range_count) {
|
||||
const ranges = indexOfLineRanges(text, line, line_range_count);
|
||||
if (ranges.len == 0) return null;
|
||||
var results = std.BoundedArray([]const u8, line_range_count){};
|
||||
var results = bun.BoundedArray([]const u8, line_range_count){};
|
||||
results.len = ranges.len;
|
||||
|
||||
for (results.slice()[0..ranges.len], ranges.slice()) |*chunk, range| {
|
||||
|
||||
Reference in New Issue
Block a user