diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2021-01-15 01:19:10 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2021-01-15 01:19:10 -0800 |
| commit | 8ff80b09ccd7e680829d0911d965ad4b0d6f7939 (patch) | |
| tree | 399da1a15ed749fa10cec8bf62dcde5e93ef3f3f /vm.c | |
| parent | 9b70cb4f624aa19c09ea73b3d9e0f50c032602c5 (diff) | |
Major overhaul of how different modes of behavior work. Approximately 2x
speedup and 2x memory footprint reduction. Also removed --mode and
VM_HIDE (~ operator), and added --context. Printing works better now.
Diffstat (limited to 'vm.c')
| -rw-r--r-- | vm.c | 29 |
1 files changed, 19 insertions, 10 deletions
@@ -122,6 +122,25 @@ static const char *match_backref(const char *str, vm_op_t *op, match_t *cap, uns // +// Find the next match after prev (or the first match if prev is NULL) +// +match_t *next_match(def_t *defs, file_t *f, match_t *prev, vm_op_t *op, unsigned int flags) +{ + const char *str; + if (prev) { + str = prev->end > prev->start ? prev->end : prev->end + 1; + recycle_if_unused(&prev); + } else { + str = f->contents; + } + for (; str < f->end; ++str) { + match_t *m = match(defs, f, str, op, flags); + if (m) return m; + } + return NULL; +} + +// // Run virtual machine operation against a string and return // a match struct, or NULL if no match is found. // The returned value should be free()'d to avoid memory leaking. @@ -316,16 +335,6 @@ match_t *match(def_t *defs, file_t *f, const char *str, vm_op_t *op, unsigned in ADD_OWNER(m->child, p); return m; } - case VM_HIDE: { - match_t *p = match(defs, f, str, op->args.pat, flags); - if (p == NULL) return NULL; - match_t *m = new_match(); - m->start = str; - m->end = p->end; - m->op = op; - ADD_OWNER(m->child, p); - return m; - } case VM_OTHERWISE: { match_t *m = match(defs, f, str, op->args.multiple.first, flags); if (m == NULL) m = match(defs, f, str, op->args.multiple.second, flags); |
