]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(struct control): Put re_compiled member at the
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 11 Apr 2006 00:49:59 +0000 (00:49 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 11 Apr 2006 00:49:59 +0000 (00:49 +0000)
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

index 862ad9d9f5c5fcb37f77631f67eca9ebcc95c9d7..44b4fc5b30e7d2b61988c83732e35e59a2075f63 100644 (file)
 /* 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);