summaryrefslogtreecommitdiff
path: root/src/font/CodepointMap.zig
diff options
context:
space:
mode:
authorMitchell Hashimoto <mitchell.hashimoto@gmail.com>2024-04-07 10:54:59 -0700
committerMitchell Hashimoto <mitchell.hashimoto@gmail.com>2024-04-07 10:54:59 -0700
commit21a648748dbc28282f7e0ea54292cebae6118c4b (patch)
tree93a347845d2f744cd9fbf8a367e73d5ce5735f28 /src/font/CodepointMap.zig
parent06df9b78679e42aff28aaa359ae1b587dd66337e (diff)
font: CodepointMap supports clone
Diffstat (limited to 'src/font/CodepointMap.zig')
-rw-r--r--src/font/CodepointMap.zig12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/font/CodepointMap.zig b/src/font/CodepointMap.zig
index c5b5b1ffb..8c9ded402 100644
--- a/src/font/CodepointMap.zig
+++ b/src/font/CodepointMap.zig
@@ -30,6 +30,18 @@ pub fn deinit(self: *CodepointMap, alloc: Allocator) void {
self.list.deinit(alloc);
}
+/// Deep copy of the struct. The given allocator is expected to
+/// be an arena allocator of some sort since the struct itself
+/// doesn't support fine-grained deallocation of fields.
+pub fn clone(self: *const CodepointMap, alloc: Allocator) !CodepointMap {
+ var list = try self.list.clone(alloc);
+ for (list.items(.descriptor)) |*d| {
+ d.* = try d.clone(alloc);
+ }
+
+ return .{ .list = list };
+}
+
/// Add an entry to the map.
///
/// For conflicting codepoints, entries added later take priority over