mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-28 10:20:05 +00:00
Optimize regex match iterator.
Reuse virtual machine and capture groups between matches.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user