mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-06 07:38:21 +00:00
terminal: add helpers to BitmapAllocator for sizing
This commit is contained in:
@@ -149,26 +149,13 @@ pub fn managedMemory(page: *const Page) void {
|
||||
_ = cimgui.c.ImGui_TableSetColumnIndex(2);
|
||||
cimgui.c.ImGui_Text("%d", page.graphemeCapacity());
|
||||
|
||||
{
|
||||
const StringAlloc = @TypeOf(page.string_alloc);
|
||||
const string_chunk = StringAlloc.bytesRequired(u8, 1);
|
||||
const string_total_chunks = page.string_alloc.bitmap_count * StringAlloc.bitmap_bit_size;
|
||||
var string_free_chunks: usize = 0;
|
||||
const string_bitmaps = page.string_alloc.bitmap.ptr(page.memory);
|
||||
for (string_bitmaps[0..page.string_alloc.bitmap_count]) |bitmap| {
|
||||
string_free_chunks += @popCount(bitmap);
|
||||
}
|
||||
const string_used_chunks = string_total_chunks - string_free_chunks;
|
||||
const string_used_bytes = string_used_chunks * string_chunk;
|
||||
const string_capacity_bytes = string_total_chunks * string_chunk;
|
||||
cimgui.c.ImGui_TableNextRow();
|
||||
_ = cimgui.c.ImGui_TableSetColumnIndex(0);
|
||||
cimgui.c.ImGui_Text("Strings (bytes)");
|
||||
_ = cimgui.c.ImGui_TableSetColumnIndex(1);
|
||||
cimgui.c.ImGui_Text("%d", string_used_bytes);
|
||||
_ = cimgui.c.ImGui_TableSetColumnIndex(2);
|
||||
cimgui.c.ImGui_Text("%d", string_capacity_bytes);
|
||||
}
|
||||
cimgui.c.ImGui_TableNextRow();
|
||||
_ = cimgui.c.ImGui_TableSetColumnIndex(0);
|
||||
cimgui.c.ImGui_Text("Strings (bytes)");
|
||||
_ = cimgui.c.ImGui_TableSetColumnIndex(1);
|
||||
cimgui.c.ImGui_Text("%d", page.string_alloc.usedBytes(page.memory));
|
||||
_ = cimgui.c.ImGui_TableSetColumnIndex(2);
|
||||
cimgui.c.ImGui_Text("%d", page.string_alloc.capacityBytes());
|
||||
|
||||
{
|
||||
const hyperlink_map = page.hyperlink_map.map(page.memory);
|
||||
|
||||
@@ -147,6 +147,20 @@ pub fn BitmapAllocator(comptime chunk_size: comptime_int) type {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the total capacity in bytes.
|
||||
pub fn capacityBytes(self: Self) usize {
|
||||
return self.bitmap_count * bitmap_bit_size * chunk_size;
|
||||
}
|
||||
|
||||
/// Returns the number of bytes currently in use.
|
||||
pub fn usedBytes(self: Self, base: anytype) usize {
|
||||
const bitmaps = self.bitmap.ptr(base);
|
||||
var free_chunks: usize = 0;
|
||||
for (bitmaps[0..self.bitmap_count]) |bitmap| free_chunks += @popCount(bitmap);
|
||||
const total_chunks = self.bitmap_count * bitmap_bit_size;
|
||||
return (total_chunks - free_chunks) * chunk_size;
|
||||
}
|
||||
|
||||
/// For testing only.
|
||||
fn isAllocated(self: *Self, base: anytype, slice: anytype) bool {
|
||||
comptime assert(@import("builtin").is_test);
|
||||
|
||||
Reference in New Issue
Block a user