diff options
| author | Jonas Maier <jonas@x77.dev> | 2026-06-06 20:49:07 +0200 |
|---|---|---|
| committer | Jonas Maier <jonas@x77.dev> | 2026-06-06 20:49:07 +0200 |
| commit | 150c732eefce15f142681b99ccdc8e22e9a05e04 (patch) | |
| tree | 249d6ef2b88876aab24d38b0136493072758e9b8 /src/regex/bc.rs | |
| parent | 24d41bb4daf081bb9cd63a2107b28b1878594ed3 (diff) | |
| download | pish-150c732eefce15f142681b99ccdc8e22e9a05e04.tar.gz | |
regex: perf
Diffstat (limited to 'src/regex/bc.rs')
| -rw-r--r-- | src/regex/bc.rs | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/src/regex/bc.rs b/src/regex/bc.rs index 6e55c7d..5de1513 100644 --- a/src/regex/bc.rs +++ b/src/regex/bc.rs @@ -147,34 +147,45 @@ impl<'p, F: Flavor> VM<'p, F> { }}; } + macro_rules! continue_thread { + ($t:expr) => {{ + let bit = $t.pc as usize; + if !self.warm.get(bit) { + self.warm.set(bit, true); + continue; + } + }}; + } + while let Some(mut thread) = self.active_threads.pop_front() { - match self.instr[thread.pc as usize] { - Instr::Class(_) | Instr::Consume(_) => { - if !self.hot.get(thread.pc as usize) { - self.hot.set(thread.pc as usize, true); - self.passive_threads.push_back(thread); + loop { + match self.instr[thread.pc as usize] { + Instr::Class(_) | Instr::Consume(_) => { + if !self.hot.get(thread.pc as usize) { + self.hot.set(thread.pc as usize, true); + self.passive_threads.push_back(thread); + } } - } - Instr::Jump(j) => { - thread.pc = j; - add_thread!(thread); - } - Instr::Fork(a, b) => { - add_thread!(Thread { - pc: b, - data: thread.data.clone(), - }); - add_thread!(Thread { - pc: a, - data: thread.data.clone(), - }); - } - Instr::Custom(instr) => { - if F::accepts(&mut thread, instr, sd) { - thread.pc += 1; - add_thread!(thread); + Instr::Jump(j) => { + thread.pc = j; + continue_thread!(thread); + } + Instr::Fork(a, b) => { + add_thread!(Thread { + pc: b, + data: thread.data.clone(), + }); + thread.pc = a; + continue_thread!(thread); + } + Instr::Custom(instr) => { + if F::accepts(&mut thread, instr, sd) { + thread.pc += 1; + continue_thread!(thread); + } } } + break; } } } @@ -257,21 +268,25 @@ struct VirtualMachine<'a> { } impl<'a> VirtualMachine<'a> { + #[inline] fn step_epsilon_1(&mut self, loc: usize) { self.vm1 .step_epsilon(&mut (loc, &self.vm0.hot, &mut self.vm2)); } + #[inline] fn step_epsilon(&mut self, loc: usize) { self.vm0.step_epsilon(&mut ()); self.step_epsilon_1(loc); } + #[inline] fn step_consume(&mut self, byte: u8) { self.vm0.step_consume(byte); self.vm1.step_consume(byte); } + #[inline] fn step(&mut self, byte: u8, loc: usize) { self.step_epsilon(loc); self.step_consume(byte); |
