mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-10-06 09:56:34 +00:00
shaper/coretext: use pointer address for cache comparison
This commit is contained in:
@@ -61,7 +61,7 @@ pub const Shaper = struct {
|
|||||||
|
|
||||||
/// The grid that our cached fonts correspond to.
|
/// The grid that our cached fonts correspond to.
|
||||||
/// If the grid changes then we need to reset our cache.
|
/// If the grid changes then we need to reset our cache.
|
||||||
cached_font_grid: ?*font.SharedGrid,
|
cached_font_grid: usize,
|
||||||
|
|
||||||
/// The list of CoreFoundation objects to release on the dedicated
|
/// The list of CoreFoundation objects to release on the dedicated
|
||||||
/// release thread. This is built up over the course of shaping and
|
/// release thread. This is built up over the course of shaping and
|
||||||
@@ -245,7 +245,7 @@ pub const Shaper = struct {
|
|||||||
.features = feats,
|
.features = feats,
|
||||||
.writing_direction = writing_direction,
|
.writing_direction = writing_direction,
|
||||||
.cached_fonts = .{},
|
.cached_fonts = .{},
|
||||||
.cached_font_grid = null,
|
.cached_font_grid = 0,
|
||||||
.cf_release_pool = .{},
|
.cf_release_pool = .{},
|
||||||
.cf_release_thread = cf_release_thread,
|
.cf_release_thread = cf_release_thread,
|
||||||
.cf_release_thr = cf_release_thr,
|
.cf_release_thr = cf_release_thr,
|
||||||
@@ -494,7 +494,11 @@ pub const Shaper = struct {
|
|||||||
) !*macos.foundation.Dictionary {
|
) !*macos.foundation.Dictionary {
|
||||||
// If this grid doesn't match the one we've cached fonts for,
|
// If this grid doesn't match the one we've cached fonts for,
|
||||||
// then we reset the cache list since it's no longer valid.
|
// then we reset the cache list since it's no longer valid.
|
||||||
if (grid != self.cached_font_grid) {
|
// We use an intFromPtr rather than direct pointer comparison
|
||||||
|
// because we don't want anyone to inadvertenly use the pointer.
|
||||||
|
const grid_id: usize = @intFromPtr(grid);
|
||||||
|
if (grid_id != self.cached_font_grid) {
|
||||||
|
if (self.cached_font_grid > 0) {
|
||||||
// Put all the currently cached fonts in to
|
// Put all the currently cached fonts in to
|
||||||
// the release pool before clearing the list.
|
// the release pool before clearing the list.
|
||||||
try self.cf_release_pool.ensureUnusedCapacity(
|
try self.cf_release_pool.ensureUnusedCapacity(
|
||||||
@@ -502,12 +506,14 @@ pub const Shaper = struct {
|
|||||||
self.cached_fonts.items.len,
|
self.cached_fonts.items.len,
|
||||||
);
|
);
|
||||||
for (self.cached_fonts.items) |ft| {
|
for (self.cached_fonts.items) |ft| {
|
||||||
if (ft) |f| self.cf_release_pool.appendAssumeCapacity(f);
|
if (ft) |f| {
|
||||||
|
self.cf_release_pool.appendAssumeCapacity(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.cached_fonts.clearRetainingCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
self.cached_fonts.clearRetainingCapacity();
|
self.cached_font_grid = grid_id;
|
||||||
|
|
||||||
self.cached_font_grid = grid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const index_int = index.int();
|
const index_int = index.int();
|
||||||
|
Reference in New Issue
Block a user