Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache file names in fill_todo #144

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use Box<OsStr> instead of OsString for filename storage
  • Loading branch information
osiewicz committed Dec 30, 2024
commit 778365def42fe56d0d6b5afa8c9d382132d23a2d
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ doctest!("../README.md");
use std::cmp;
use std::cmp::Ordering;
use std::error::Error;
use std::ffi::OsString;
use std::ffi::OsStr;
use std::fmt;
use std::fs;
use std::fs::DirEntry;
Expand Down Expand Up @@ -330,11 +330,11 @@ impl fmt::Display for GlobError {
struct PathWrapper {
path: PathBuf,
is_directory: bool,
file_name: Option<OsString>,
file_name: Option<Box<OsStr>>,
}

impl PathWrapper {
fn from_dir_entry(path: PathBuf, file_name: Option<OsString>, e: DirEntry) -> Self {
fn from_dir_entry(path: PathBuf, file_name: Option<Box<OsStr>>, e: DirEntry) -> Self {
let is_directory = e
.file_type()
.ok()
Expand All @@ -357,7 +357,7 @@ impl PathWrapper {
}
fn from_path(path: PathBuf) -> Self {
let is_directory = fs::metadata(&path).map(|m| m.is_dir()).unwrap_or(false);
let file_name = path.file_name().map(ToOwned::to_owned);
let file_name = path.file_name().map(Box::from);
Self {
path,
is_directory,
Expand Down Expand Up @@ -944,10 +944,10 @@ fn fill_todo(
let (path, file_name) = if curdir {
let path = e.path();
let file_name = path.file_name().unwrap();
(PathBuf::from(file_name), Some(file_name.to_owned()))
(PathBuf::from(file_name), Some(Box::from(file_name)))
} else {
let path = e.path();
let file_name = path.file_name().map(ToOwned::to_owned);
let file_name = path.file_name().map(Box::from);
(path, file_name)
};
PathWrapper::from_dir_entry(path, file_name, e)
Expand Down
Loading