mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-05-19 09:40:22 -07:00
Only create the Grep searcher once.
This commit is contained in:
parent
fd3e5069b6
commit
9948e0ca07
16
src/args.rs
16
src/args.rs
@ -192,6 +192,7 @@ pub struct Args {
|
|||||||
files: bool,
|
files: bool,
|
||||||
follow: bool,
|
follow: bool,
|
||||||
glob_overrides: Option<Gitignore>,
|
glob_overrides: Option<Gitignore>,
|
||||||
|
grep: Grep,
|
||||||
heading: bool,
|
heading: bool,
|
||||||
hidden: bool,
|
hidden: bool,
|
||||||
ignore_case: bool,
|
ignore_case: bool,
|
||||||
@ -283,6 +284,12 @@ impl RawArgs {
|
|||||||
btypes.add_defaults();
|
btypes.add_defaults();
|
||||||
try!(self.add_types(&mut btypes));
|
try!(self.add_types(&mut btypes));
|
||||||
let types = try!(btypes.build());
|
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 {
|
let mut args = Args {
|
||||||
pattern: pattern,
|
pattern: pattern,
|
||||||
paths: paths,
|
paths: paths,
|
||||||
@ -295,6 +302,7 @@ impl RawArgs {
|
|||||||
files: self.flag_files,
|
files: self.flag_files,
|
||||||
follow: self.flag_follow,
|
follow: self.flag_follow,
|
||||||
glob_overrides: glob_overrides,
|
glob_overrides: glob_overrides,
|
||||||
|
grep: grep,
|
||||||
heading: !self.flag_no_heading && self.flag_heading,
|
heading: !self.flag_no_heading && self.flag_heading,
|
||||||
hidden: self.flag_hidden,
|
hidden: self.flag_hidden,
|
||||||
ignore_case: self.flag_ignore_case,
|
ignore_case: self.flag_ignore_case,
|
||||||
@ -378,12 +386,8 @@ impl Args {
|
|||||||
/// basic searching of regular expressions in a single buffer.
|
/// basic searching of regular expressions in a single buffer.
|
||||||
///
|
///
|
||||||
/// The pattern and other flags are taken from the command line.
|
/// The pattern and other flags are taken from the command line.
|
||||||
pub fn grep(&self) -> Result<Grep> {
|
pub fn grep(&self) -> Grep {
|
||||||
GrepBuilder::new(&self.pattern)
|
self.grep.clone()
|
||||||
.case_insensitive(self.ignore_case)
|
|
||||||
.line_terminator(self.eol)
|
|
||||||
.build()
|
|
||||||
.map_err(From::from)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a new input buffer that is used in searching.
|
/// Creates a new input buffer that is used in searching.
|
||||||
|
@ -99,7 +99,7 @@ fn run(args: Args) -> Result<u64> {
|
|||||||
chan_work: stealer.clone(),
|
chan_work: stealer.clone(),
|
||||||
inpbuf: args.input_buffer(),
|
inpbuf: args.input_buffer(),
|
||||||
outbuf: Some(vec![]),
|
outbuf: Some(vec![]),
|
||||||
grep: try!(args.grep()),
|
grep: args.grep(),
|
||||||
match_count: 0,
|
match_count: 0,
|
||||||
};
|
};
|
||||||
workers.push(thread::spawn(move || worker.run()));
|
workers.push(thread::spawn(move || worker.run()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user