Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Jul 2000 03:58:08 -0700 (PDT)
From:      "Daniel C. Sobral" <dcs@FreeBSD.org>
To:        cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org
Subject:   cvs commit: src/lib/libc/regex engine.c regcomp.c regex2.h
Message-ID:  <200007021058.DAA29055@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
dcs         2000/07/02 03:58:08 PDT

  Modified files:
    lib/libc/regex       engine.c regcomp.c regex2.h 
  Log:
  Enhance the optimization provided by pre-matching. Fix style bugs with
  previous commits.
  
  At the time we search the pattern for the "must" string, we now compute
  the longest offset from the beginning of the pattern at which the must
  string might be found. If that offset is found to be infinite (through
  use of "+" or "*"), we set it to -1 to disable the heuristics applied
  later.
  
  After we are done with pre-matching, we use that offset and the point in
  the text at which the must string was found to compute the earliest
  point at which the pattern might be found.
  
  Special care should be taken here. The variable "start" is passed to the
  automata-processing functions fast() and slow() to indicate the point in
  the text at which they should start working from. The real beginning of
  the text is passed in a struct match variable m, which is used to check
  for anchors. That variable, though, is initialized with "start", so we
  must not adjust "start" before "m" is properly initialized.
  
  Simple tests showed a speed increase from 100% to 400%, but they were
  biased in that regexec() was called for the whole file instead of line
  by line, and parenthized subexpressions were not searched for.
  
  This change adds a single integer to the size of the "guts" structure,
  and does not change the ABI.
  
  Further improvements possible:
  
  Since the speed increase observed here is so huge, one intuitive
  optimization would be to introduce a bias in the function that computes
  the "must" string so as to prefer a smaller string with a finite offset
  over a larger one with an infinite offset. Tests have shown this to be a
  bad idea, though, as the cost of false pre-matches far outweights the
  benefits of a must offset, even in biased situations.
  
  A number of other improvements suggest themselves, though:
  
  	* identify the cases where the pattern is identical to the must
  	string, and avoid entering fast() and slow() in these cases.
  
  	* compute the maximum offset from the must string to the end of
  	the pattern, and use that to set the point at which fast() and
  	slow() should give up trying to find a match, and return then
  	return to pre-matching.
  
  	* return all the way to pre-matching if a "match" was found and
  	later invalidated by back reference processing. Since back
  	references are evil and should be avoided anyway, this is of
  	little use.
  
  Revision  Changes    Path
  1.7       +13 -8     src/lib/libc/regex/engine.c
  1.16      +165 -6    src/lib/libc/regex/regcomp.c
  1.5       +2 -1      src/lib/libc/regex/regex2.h



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200007021058.DAA29055>