Remove unnecessary Box::leak
This commit is contained in:
@@ -46,7 +46,7 @@ impl Config {
|
||||
.arg(
|
||||
Arg::with_name("only match")
|
||||
.short("o")
|
||||
.help("Only print matched text")
|
||||
.help("Only print matched text"),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
|
||||
22
src/main.rs
22
src/main.rs
@@ -3,7 +3,7 @@ use rack::filematch::*;
|
||||
use std::fs::{self, DirEntry, File};
|
||||
use std::io;
|
||||
use std::io::prelude::*;
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
extern crate term;
|
||||
|
||||
@@ -12,13 +12,14 @@ fn main() {
|
||||
|
||||
let search_path = &config.path;
|
||||
let path = if search_path.starts_with('/') {
|
||||
Path::new(search_path)
|
||||
PathBuf::from(search_path)
|
||||
} else {
|
||||
let p: &'static str = Box::leak(Box::new(String::from("./") + search_path));
|
||||
Path::new(p)
|
||||
let mut path = String::from("./");
|
||||
path.push_str(search_path);
|
||||
PathBuf::from(path)
|
||||
};
|
||||
|
||||
let results = traverse_dir(&config, path, Option::None, |config, path| {
|
||||
let results = traverse_dir(&config, &path, Option::None, |config, path| {
|
||||
check_file(config, path)
|
||||
});
|
||||
match results {
|
||||
@@ -30,7 +31,7 @@ fn main() {
|
||||
|
||||
fn traverse_dir(
|
||||
config: &Config,
|
||||
dir: &Path,
|
||||
dir: &PathBuf,
|
||||
gitignore_entries: Option<Vec<String>>,
|
||||
operation: fn(&Config, &Path) -> io::Result<FileMatch>,
|
||||
) -> io::Result<Vec<FileMatch>> {
|
||||
@@ -71,18 +72,15 @@ fn traverse_dir(
|
||||
// TODO: Should borrow gitignore instead of cloning..
|
||||
let mut results =
|
||||
traverse_dir(&config, &entry.path(), Some(gitignore.clone()), operation)?;
|
||||
let has_results = results
|
||||
.iter()
|
||||
.filter(|mat| !mat.matches.is_empty())
|
||||
.count()
|
||||
> 0;
|
||||
let has_results = results.iter().filter(|mat| !mat.matches.is_empty()).count() > 0;
|
||||
|
||||
if has_results {
|
||||
matches.append(&mut results);
|
||||
}
|
||||
} else {
|
||||
if config.use_gitignore {
|
||||
let should_ignore: Option<&String> = gitignore.iter().find(|&line| path.contains(&line.clone()));
|
||||
let should_ignore: Option<&String> =
|
||||
gitignore.iter().find(|&line| path.contains(&line.clone()));
|
||||
|
||||
if !should_ignore.unwrap_or(&String::from("")).is_empty()
|
||||
|| entry.path().to_str().unwrap().contains("/.git")
|
||||
|
||||
Reference in New Issue
Block a user