also looking at this
Port to latest zig-master
#2
53 files
+1149
-1017
| @@ -43,7 +43,7 @@ const std = @import("std"); | ||
| 43 | 43 | /// var gpa = std.heap.GeneralPurposeAllocator(.{}){}; |
| 44 | 44 | /// const allocator = gpa.allocator(); |
| 45 | 45 | /// |
| 46 | /// const regex = try Regex.compile(allocator, "\\d+"); | |
| 46 | /// const regex = try Regex.compile(allocator, init.io, "\\d+"); | |
| 47 | 47 | /// defer regex.deinit(); |
| 48 | 48 | /// |
| 49 | 49 | /// // Thread 1 |
| @@ -115,12 +115,12 @@ pub fn SharedRegex(comptime Regex: type) type { | ||
| 115 | 115 | allocator: std.mem.Allocator, |
| 116 | 116 | |
| 117 | 117 | /// Initialize a shared regex pattern |
| 118 | pub fn init(allocator: std.mem.Allocator, pattern: []const u8) !*Self { | |
| 118 | pub fn init(allocator: std.mem.Allocator, io: std.Io, pattern: []const u8) !*Self { | |
| 119 | 119 | const self = try allocator.create(Self); |
| 120 | 120 | errdefer allocator.destroy(self); |
| 121 | 121 | |
| 122 | 122 | self.* = .{ |
| 123 | .regex = try Regex.compile(allocator, pattern), | |
| 123 | .regex = try Regex.compile(allocator, io, pattern), | |
| 124 | 124 | .ref_count = std.atomic.Value(usize).init(1), |
| 125 | 125 | .allocator = allocator, |
| 126 | 126 | }; |
| @@ -198,11 +198,13 @@ pub fn RegexCache(comptime Regex: type) type { | ||
| 198 | 198 | }; |
| 199 | 199 | |
| 200 | 200 | cache: std.StringHashMap(Regex), |
| 201 | io: std.Io, | |
| 201 | 202 | allocator: std.mem.Allocator, |
| 202 | 203 | initialized: bool = false, |
| 203 | 204 | |
| 204 | pub fn init(allocator: std.mem.Allocator) Self { | |
| 205 | pub fn init(allocator: std.mem.Allocator, io: std.Io) Self { | |
| 205 | 206 | return .{ |
| 207 | .io = io, | |
| 206 | 208 | .cache = std.StringHashMap(Regex).init(allocator), |
| 207 | 209 | .allocator = allocator, |
| 208 | 210 | .initialized = true, |
| @@ -229,7 +231,7 @@ pub fn RegexCache(comptime Regex: type) type { | ||
| 229 | 231 | } |
| 230 | 232 | |
| 231 | 233 | // Not in cache, compile and store |
| 232 | const regex = try Regex.compile(self.allocator, pattern); | |
| 234 | const regex = try Regex.compile(self.allocator,self.io, pattern); | |
| 233 | 235 | errdefer { |
| 234 | 236 | var mut_regex = regex; |
| 235 | 237 | mut_regex.deinit(); |