mirror of
https://github.com/Llewellynvdm/exa.git
synced 2025-04-01 13:21:50 +00:00
Actually, cache the calls to ext
They get computed often enough for this to be worthwhile, and I have plans for using the extension even if it's not what's being sorted by.
This commit is contained in:
parent
184de0ce79
commit
7063c21ba0
12
file.rs
12
file.rs
@ -11,6 +11,7 @@ use unix::{get_user_name, get_group_name};
|
||||
// result around with the file for safe keeping.
|
||||
pub struct File<'a> {
|
||||
pub name: &'a str,
|
||||
pub ext: Option<&'a str>,
|
||||
pub path: &'a Path,
|
||||
pub stat: io::FileStat,
|
||||
}
|
||||
@ -28,12 +29,17 @@ impl<'a> File<'a> {
|
||||
Err(e) => fail!("Couldn't stat {}: {}", filename, e),
|
||||
};
|
||||
|
||||
return File { path: path, stat: stat, name: filename };
|
||||
return File {
|
||||
path: path,
|
||||
stat: stat,
|
||||
name: filename,
|
||||
ext: File::ext(filename),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn ext(&self) -> Option<&'a str> {
|
||||
fn ext(name: &'a str) -> Option<&'a str> {
|
||||
let re = regex!(r"\.(.+)$");
|
||||
re.captures(self.name).map(|caps| caps.at(1))
|
||||
re.captures(name).map(|caps| caps.at(1))
|
||||
}
|
||||
|
||||
pub fn is_dotfile(&self) -> bool {
|
||||
|
@ -25,7 +25,7 @@ impl SortField {
|
||||
Name => files.sort_by(|a, b| a.name.cmp(&b.name)),
|
||||
Size => files.sort_by(|a, b| a.stat.size.cmp(&b.stat.size)),
|
||||
Extension => files.sort_by(|a, b| {
|
||||
let exts = a.ext().cmp(&b.ext());
|
||||
let exts = a.ext.cmp(&b.ext);
|
||||
let names = a.name.cmp(&b.name);
|
||||
lexical_ordering(exts, names)
|
||||
}),
|
||||
|
Loading…
x
Reference in New Issue
Block a user