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:
Jarred Sumner
2025-08-28 17:34:35 -07:00
committed by GitHub
parent c69ed120e9
commit fe8f8242fd
18 changed files with 342 additions and 29 deletions

View File

@@ -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| {