Moved pattern code into the right file

This commit is contained in:
Bruce Hill 2021-01-15 19:39:28 -08:00
parent 13c4564594
commit 3d3a73e18c
4 changed files with 23 additions and 23 deletions

21
match.c
View File

@ -664,25 +664,4 @@ size_t free_all_matches(void)
}
#endif
//
// Deallocate memory referenced inside a pattern struct
//
void destroy_pat(pat_t *pat)
{
switch (pat->type) {
case VM_STRING: case VM_REF:
xfree(&pat->args.s);
break;
case VM_CAPTURE:
if (pat->args.capture.name)
xfree(&pat->args.capture.name);
break;
case VM_REPLACE:
if (pat->args.replace.text)
xfree(&pat->args.replace.text);
break;
default: break;
}
}
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1

View File

@ -14,8 +14,6 @@ __attribute__((hot, nonnull(2,3,4)))
match_t *match(def_t *defs, file_t *f, const char *str, pat_t *pat, unsigned int flags);
__attribute__((nonnull))
match_t *get_capture(match_t *m, const char **id);
__attribute__((nonnull))
void destroy_pat(pat_t *pat);
match_t *new_match(void);
__attribute__((nonnull))
void recycle_if_unused(match_t **at_m);

View File

@ -613,4 +613,25 @@ def_t *bp_definition(file_t *f, const char *str)
return def;
}
//
// Deallocate memory referenced inside a pattern struct
//
void destroy_pat(pat_t *pat)
{
switch (pat->type) {
case VM_STRING: case VM_REF:
xfree(&pat->args.s);
break;
case VM_CAPTURE:
if (pat->args.capture.name)
xfree(&pat->args.capture.name);
break;
case VM_REPLACE:
if (pat->args.replace.text)
xfree(&pat->args.replace.text);
break;
default: break;
}
}
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1

View File

@ -19,6 +19,8 @@ __attribute__((nonnull))
pat_t *bp_pattern(file_t *f, const char *str);
__attribute__((nonnull))
def_t *bp_definition(file_t *f, const char *str);
__attribute__((nonnull))
void destroy_pat(pat_t *pat);
#endif
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1