Skip to content

Commit

Permalink
pcre2: use jit_if_available
Browse files Browse the repository at this point in the history
This will allow PCRE2 to fall back to non-JIT matching when running on
platforms without JIT support.

ref BurntSushi/rust-pcre2#3
  • Loading branch information
BurntSushi committed Sep 8, 2018
1 parent 0f74942 commit eb18da0
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 17 deletions.
17 changes: 8 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ members = [
]

[dependencies]
grep = { version = "0.2.2", path = "grep" }
grep = { version = "0.2.3", path = "grep" }
ignore = { version = "0.4.4", path = "ignore" }
lazy_static = "1.1.0"
log = "0.4.5"
Expand Down
4 changes: 2 additions & 2 deletions grep-pcre2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grep-pcre2"
version = "0.1.1" #:version
version = "0.1.2" #:version
authors = ["Andrew Gallant <[email protected]>"]
description = """
Use PCRE2 with the 'grep' crate.
Expand All @@ -14,4 +14,4 @@ license = "Unlicense/MIT"

[dependencies]
grep-matcher = { version = "0.1.1", path = "../grep-matcher" }
pcre2 = "0.1.0"
pcre2 = "0.1.1"
22 changes: 20 additions & 2 deletions grep-pcre2/src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,34 @@ impl RegexMatcherBuilder {
self
}

/// Enable PCRE2's JIT.
/// Enable PCRE2's JIT and return an error if it's not available.
///
/// This generally speeds up matching quite a bit. The downside is that it
/// can increase the time it takes to compile a pattern.
///
/// This is disabled by default.
/// If the JIT isn't available or if JIT compilation returns an error, then
/// regex compilation will fail with the corresponding error.
///
/// This is disabled by default, and always overrides `jit_if_available`.
pub fn jit(&mut self, yes: bool) -> &mut RegexMatcherBuilder {
self.builder.jit(yes);
self
}

/// Enable PCRE2's JIT if it's available.
///
/// This generally speeds up matching quite a bit. The downside is that it
/// can increase the time it takes to compile a pattern.
///
/// If the JIT isn't available or if JIT compilation returns an error,
/// then a debug message with the error will be emitted and the regex will
/// otherwise silently fall back to non-JIT matching.
///
/// This is disabled by default, and always overrides `jit`.
pub fn jit_if_available(&mut self, yes: bool) -> &mut RegexMatcherBuilder {
self.builder.jit_if_available(yes);
self
}
}

/// An implementation of the `Matcher` trait using PCRE2.
Expand Down
4 changes: 2 additions & 2 deletions grep/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "grep"
version = "0.2.2" #:version
version = "0.2.3" #:version
authors = ["Andrew Gallant <[email protected]>"]
description = """
Fast line oriented regex searching as a library.
Expand All @@ -15,7 +15,7 @@ license = "Unlicense/MIT"
[dependencies]
grep-cli = { version = "0.1.1", path = "../grep-cli" }
grep-matcher = { version = "0.1.1", path = "../grep-matcher" }
grep-pcre2 = { version = "0.1.1", path = "../grep-pcre2", optional = true }
grep-pcre2 = { version = "0.1.2", path = "../grep-pcre2", optional = true }
grep-printer = { version = "0.1.1", path = "../grep-printer" }
grep-regex = { version = "0.1.1", path = "../grep-regex" }
grep-searcher = { version = "0.1.1", path = "../grep-searcher" }
Expand Down
2 changes: 1 addition & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ impl ArgMatches {
// For whatever reason, the JIT craps out during regex compilation with
// a "no more memory" error on 32 bit systems. So don't use it there.
if !cfg!(target_pointer_width = "32") {
builder.jit(true);
builder.jit_if_available(true);
}
if self.pcre2_unicode() {
builder.utf(true).ucp(true);
Expand Down

0 comments on commit eb18da0

Please sign in to comment.