mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-20 18:56:08 +03:00
font: descritor can hash using a hasher
This commit is contained in:
@ -53,7 +53,7 @@ const DescriptorCache = std.HashMapUnmanaged(
|
|||||||
|
|
||||||
pub fn hash(ctx: @This(), k: KeyType) u64 {
|
pub fn hash(ctx: @This(), k: KeyType) u64 {
|
||||||
_ = ctx;
|
_ = ctx;
|
||||||
return k.hash();
|
return k.hashcode();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eql(ctx: @This(), a: KeyType, b: KeyType) bool {
|
pub fn eql(ctx: @This(), a: KeyType, b: KeyType) bool {
|
||||||
|
@ -57,27 +57,31 @@ pub const Descriptor = struct {
|
|||||||
/// will be preferred, but not guaranteed.
|
/// will be preferred, but not guaranteed.
|
||||||
variations: []const Variation = &.{},
|
variations: []const Variation = &.{},
|
||||||
|
|
||||||
/// Returns a hash code that can be used to uniquely identify this
|
/// Hash the descriptor with the given hasher.
|
||||||
/// action.
|
pub fn hash(self: Descriptor, hasher: anytype) void {
|
||||||
pub fn hash(self: Descriptor) u64 {
|
|
||||||
const autoHash = std.hash.autoHash;
|
const autoHash = std.hash.autoHash;
|
||||||
var hasher = std.hash.Wyhash.init(0);
|
autoHash(hasher, self.family);
|
||||||
autoHash(&hasher, self.family);
|
autoHash(hasher, self.style);
|
||||||
autoHash(&hasher, self.style);
|
autoHash(hasher, self.codepoint);
|
||||||
autoHash(&hasher, self.codepoint);
|
autoHash(hasher, self.size);
|
||||||
autoHash(&hasher, self.size);
|
autoHash(hasher, self.bold);
|
||||||
autoHash(&hasher, self.bold);
|
autoHash(hasher, self.italic);
|
||||||
autoHash(&hasher, self.italic);
|
autoHash(hasher, self.monospace);
|
||||||
autoHash(&hasher, self.monospace);
|
autoHash(hasher, self.variations.len);
|
||||||
autoHash(&hasher, self.variations.len);
|
|
||||||
for (self.variations) |variation| {
|
for (self.variations) |variation| {
|
||||||
autoHash(&hasher, variation.id);
|
autoHash(hasher, variation.id);
|
||||||
|
|
||||||
// This is not correct, but we don't currently depend on the
|
// This is not correct, but we don't currently depend on the
|
||||||
// hash value being different based on decimal values of variations.
|
// hash value being different based on decimal values of variations.
|
||||||
autoHash(&hasher, @as(u64, @intFromFloat(variation.value)));
|
autoHash(hasher, @as(u64, @intFromFloat(variation.value)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a hash code that can be used to uniquely identify this
|
||||||
|
/// action.
|
||||||
|
pub fn hashcode(self: Descriptor) u64 {
|
||||||
|
var hasher = std.hash.Wyhash.init(0);
|
||||||
|
self.hash(&hasher);
|
||||||
return hasher.final();
|
return hasher.final();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,7 +556,7 @@ test "descriptor hash" {
|
|||||||
const testing = std.testing;
|
const testing = std.testing;
|
||||||
|
|
||||||
var d: Descriptor = .{};
|
var d: Descriptor = .{};
|
||||||
try testing.expect(d.hash() != 0);
|
try testing.expect(d.hashcode() != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "descriptor hash familiy names" {
|
test "descriptor hash familiy names" {
|
||||||
@ -560,7 +564,7 @@ test "descriptor hash familiy names" {
|
|||||||
|
|
||||||
var d1: Descriptor = .{ .family = "A" };
|
var d1: Descriptor = .{ .family = "A" };
|
||||||
var d2: Descriptor = .{ .family = "B" };
|
var d2: Descriptor = .{ .family = "B" };
|
||||||
try testing.expect(d1.hash() != d2.hash());
|
try testing.expect(d1.hashcode() != d2.hashcode());
|
||||||
}
|
}
|
||||||
|
|
||||||
test "fontconfig" {
|
test "fontconfig" {
|
||||||
|
Reference in New Issue
Block a user