From ff652937b0f2ca7443811db6ec44f054472bf1c3 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 11 Apr 2006 00:49:59 +0000 Subject: (struct control): Put re_compiled member at the end, since it's large. Change regexpr member from char * to bool; all uses changed. Add new member fastmap. (extract_regexp): regexp arg is now char const *, not char *. Don't bother duplicating the regular expression; it's not needed. Set fastmap from new fastmap member. Don't bother allocating a buffer, as the regexp code does a better job than we do. --- src/csplit.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/csplit.c') diff --git a/src/csplit.c b/src/csplit.c index 862ad9d9f..44b4fc5b3 100644 --- a/src/csplit.c +++ b/src/csplit.c @@ -61,14 +61,15 @@ /* A compiled pattern arg. */ struct control { - char *regexpr; /* Non-compiled regular expression. */ - struct re_pattern_buffer re_compiled; /* Compiled regular expression. */ intmax_t offset; /* Offset from regexp to split at. */ uintmax_t lines_required; /* Number of lines required. */ uintmax_t repeat; /* Repeat count. */ int argnum; /* ARGV index. */ bool repeat_forever; /* True if `*' used as a repeat count. */ bool ignore; /* If true, produce no output (for regexp). */ + bool regexpr; /* True if regular expression was used. */ + struct re_pattern_buffer re_compiled; /* Compiled regular expression. */ + char fastmap[UCHAR_MAX + 1]; /* Fastmap for RE_COMPILED. */ }; /* Initial size of data area in buffers. */ @@ -1038,7 +1039,7 @@ new_control_record (void) if (control_used == control_allocated) controls = X2NREALLOC (controls, &control_allocated); p = &controls[control_used++]; - p->regexpr = NULL; + p->regexpr = false; p->repeat = 0; p->repeat_forever = false; p->lines_required = 0; @@ -1097,11 +1098,11 @@ parse_repeat_count (int argnum, struct control *p, char *str) Unless IGNORE is true, mark these lines for output. */ static struct control * -extract_regexp (int argnum, bool ignore, char *str) +extract_regexp (int argnum, bool ignore, char const *str) { size_t len; /* Number of bytes in this regexp. */ char delim = *str; - char *closing_delim; + char const *closing_delim; struct control *p; const char *err; @@ -1115,13 +1116,12 @@ extract_regexp (int argnum, bool ignore, char *str) p->argnum = argnum; p->ignore = ignore; - p->regexpr = xmalloc (len + 1); - strncpy (p->regexpr, str + 1, len); - p->re_compiled.allocated = len * 2; - p->re_compiled.buffer = xmalloc (p->re_compiled.allocated); - p->re_compiled.fastmap = xmalloc (1 << CHAR_BIT); + p->regexpr = true; + p->re_compiled.buffer = NULL; + p->re_compiled.allocated = 0; + p->re_compiled.fastmap = p->fastmap; p->re_compiled.translate = NULL; - err = re_compile_pattern (p->regexpr, len, &p->re_compiled); + err = re_compile_pattern (str + 1, len, &p->re_compiled); if (err) { error (0, 0, _("%s: invalid regular expression: %s"), str, err); -- cgit v1.2.3-54-g00ecf