summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2016-09-06 19:33:19 -0400
committerAndrew Gallant <jamslam@gmail.com>2016-09-06 19:33:19 -0400
commit9948e0ca07ffbdc40a5024e553646568fd3ab97b (patch)
tree36d8e90a2789040506816aba5e1d0325179d8781 /src
parentfd3e5069b6a4149e82789d5e1aad9fb7a8b49a77 (diff)
Only create the Grep searcher once.
Diffstat (limited to 'src')
-rw-r--r--src/args.rs16
-rw-r--r--src/main.rs2
2 files changed, 11 insertions, 7 deletions
diff --git a/src/args.rs b/src/args.rs
index c2b14f7c..ed129439 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -192,6 +192,7 @@ pub struct Args {
files: bool,
follow: bool,
glob_overrides: Option<Gitignore>,
+ grep: Grep,
heading: bool,
hidden: bool,
ignore_case: bool,
@@ -283,6 +284,12 @@ impl RawArgs {
btypes.add_defaults();
try!(self.add_types(&mut btypes));
let types = try!(btypes.build());
+ let grep = try!(
+ GrepBuilder::new(&pattern)
+ .case_insensitive(self.flag_ignore_case)
+ .line_terminator(eol)
+ .build()
+ );
let mut args = Args {
pattern: pattern,
paths: paths,
@@ -295,6 +302,7 @@ impl RawArgs {
files: self.flag_files,
follow: self.flag_follow,
glob_overrides: glob_overrides,
+ grep: grep,
heading: !self.flag_no_heading && self.flag_heading,
hidden: self.flag_hidden,
ignore_case: self.flag_ignore_case,
@@ -378,12 +386,8 @@ impl Args {
/// basic searching of regular expressions in a single buffer.
///
/// The pattern and other flags are taken from the command line.
- pub fn grep(&self) -> Result<Grep> {
- GrepBuilder::new(&self.pattern)
- .case_insensitive(self.ignore_case)
- .line_terminator(self.eol)
- .build()
- .map_err(From::from)
+ pub fn grep(&self) -> Grep {
+ self.grep.clone()
}
/// Creates a new input buffer that is used in searching.
diff --git a/src/main.rs b/src/main.rs
index 55be1969..10611907 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -99,7 +99,7 @@ fn run(args: Args) -> Result<u64> {
chan_work: stealer.clone(),
inpbuf: args.input_buffer(),
outbuf: Some(vec![]),
- grep: try!(args.grep()),
+ grep: args.grep(),
match_count: 0,
};
workers.push(thread::spawn(move || worker.run()));