Skip to content

Commit

Permalink
add internal control *LOOK-AHEAD-FOR-SUFFIX*
Browse files Browse the repository at this point in the history
This allows better performance for some scanning use-cases.

We also bump the minor version to 2.1.0.
  • Loading branch information
Robert Smith authored and stassats committed Aug 5, 2018
1 parent d01bbf7 commit 2115632
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
7 changes: 6 additions & 1 deletion api.lisp
Expand Up @@ -31,6 +31,10 @@

(in-package :cl-ppcre)

(defvar *look-ahead-for-suffix* t
"Controls whether scanners will optimistically look ahead for a
constant suffix of a regular expression, if there is one.")

(defgeneric create-scanner (regex &key case-insensitive-mode
multi-line-mode
single-line-mode
Expand Down Expand Up @@ -120,7 +124,8 @@ modify its first argument \(but only if it's a parse tree)."))
(end-string (end-string regex))
;; if we found a non-zero-length end-string we create an
;; efficient search function for it
(end-string-test (and end-string
(end-string-test (and *look-ahead-for-suffix*
end-string
(plusp (len end-string))
(if (= 1 (len end-string))
(create-char-searcher
Expand Down
2 changes: 1 addition & 1 deletion cl-ppcre.asd
Expand Up @@ -37,7 +37,7 @@
(in-package :cl-ppcre-asd)

(defsystem :cl-ppcre
:version "2.0.11"
:version "2.1.0"
:description "Perl-compatible regular expression library"
:author "Dr. Edi Weitz"
:license "BSD"
Expand Down
26 changes: 26 additions & 0 deletions docs/index.html
Expand Up @@ -103,6 +103,7 @@ <h2>CL-PPCRE - Portable Perl-compatible regular expressions for Common Lisp</h2>
<li><a href="#*optimize-char-classes*"><code>*optimize-char-classes*</code></a>
<li><a href="#*allow-quoting*"><code>*allow-quoting*</code></a>
<li><a href="#*allow-named-registers*"><code>*allow-named-registers*</code></a>
<li><a href="#*look-ahead-for-suffix*"><code>*look-ahead-for-suffix*</code></a>
</ol>
<li><a href="#misc">Miscellaneous</a>
<ol>
Expand Down Expand Up @@ -1391,6 +1392,31 @@ <h4><a name="modify" class=none>Modifying scanner behaviour</a></h4>
time.</blockquote>
</blockquote>

<p><br>[Special variable]
<br><a class=none name="*look-ahead-for-suffix*"><b>*look-ahead-for-suffix*</b></a>

<blockquote><br>Given a regular expression which has a constant
suffix, such as <code>(a|b)+x</code> whose constant suffix
is <code>x</code>, the scanners created
by <a href="#create-scanner"><code>CREATE-SCANNER</code></a> will
attempt to optimize by searching for the position of the suffix prior
to performing the full match. In many cases, this is an optimization,
especially when backtracking is involved on small strings. However, in
other cases, such as incremental parsing of a very large string, this
can cause a degradation in performance, because the entire string is
searched for the suffix before an otherwise easy prefix match failure
can occur. The variable <code>*LOOK-AHEAD-FOR-SUFFIX*</code>, whose
default is <code>T</code>, can be used to selectively control this
behavior.
<p>
Note: Due to the nature of <a href="http://www.lispworks.com/documentation/HyperSpec/Body/s_ld_tim.htm"><code>LOAD-TIME-VALUE</code></a> and the <a
href="#compiler-macro">compiler macro for <code>SCAN</code> and other functions</a>, some
scanners might be created in a <a
href="http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_n.htm#null_lexical_environment">null
lexical environment</a> at load time or at compile time so be careful
to which value <code>*LOOK-AHEAD-FOR-SUFFIX*</code> is bound at that
time.</blockquote>

<h4><a name="misc" class=none>Miscellaneous</a></h4>

<p><br>[Function]
Expand Down
1 change: 1 addition & 0 deletions packages.lisp
Expand Up @@ -59,6 +59,7 @@
:*allow-named-registers*
:*optimize-char-classes*
:*property-resolver*
:*look-ahead-for-suffix*
:ppcre-error
:ppcre-invocation-error
:ppcre-syntax-error
Expand Down

0 comments on commit 2115632

Please sign in to comment.