Optimize regex match iterator.

Reuse virtual machine and capture groups between matches.
This commit is contained in:
Jeroen van Rijn
2025-04-07 14:58:41 +02:00
parent c13b68f103
commit a5e513567b
3 changed files with 51 additions and 19 deletions
@@ -627,8 +627,9 @@ opcode_count :: proc(code: Program) -> (opcodes: int) {
return
}
create :: proc(code: Program, str: string) -> (vm: Machine) {
create :: proc(code: Program, str: string, allocator := context.allocator) -> (vm: Machine) {
assert(len(code) > 0, "RegEx VM has no instructions.")
context.allocator = allocator
vm.memory = str
vm.code = code
@@ -644,3 +645,11 @@ create :: proc(code: Program, str: string) -> (vm: Machine) {
return
}
destroy :: proc(vm: Machine, allocator := context.allocator) {
context.allocator = allocator
delete(vm.busy_map)
free(vm.threads)
free(vm.next_threads)
}