Skip to content
Myr

globset: reduce owned path copying in globset

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Closes #3454

authored by kmg0308 · committed by Andrew Gallant · parent 3a57099 · Browse files · 2 files+21 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+21 added−13 removed

  • other:+21 added−13 removed

2 files+21 added−13 removed

modified:crates/globset/src/lib.rs+1 added-1 removed
381 unmodified lines
382383 /// Returns true if all globs in this set match the path given.384 ///385 /// This takes a Candidate as input, which can be used to amortize the cost386 /// of peparing a path for matching.386 /// of preparing a path for matching.387 ///388 /// This will return true if the set of globs is empty, as in that case all389 /// `0` of the globs will match.390 pub fn matches_all_candidate(&self, path: &Candidate<'_>) -> bool {
749 unmodified lines
modified:crates/globset/src/pathutil.rs+20 added-12 removed
1use std::borrow::Cow;23use bstr::{ByteSlice, ByteVec};3use bstr::ByteSlice;45/// The final component of the path, if it is a normal file.6///7/// If the path terminates in `..`, or consists solely of a root of prefix,
4 unmodified lines
12 }13 let last_slash = path.rfind_byte(b'/').map(|i| i + 1).unwrap_or(0);14 let got = match *path {15 Cow::Borrowed(path) => Cow::Borrowed(&path[last_slash..]),16 Cow::Owned(ref path) => {17 let mut path = path.clone();18 path.drain_bytes(..last_slash);19 Cow::Owned(path)20 }16 Cow::Owned(ref path) => Cow::Owned(path[last_slash..].to_vec()),17 };18 if got == &b".."[..] {19 return None;20 }
27 unmodified lines
48 Some(i) => i,49 };50 Some(match *name {51 Cow::Borrowed(name) => Cow::Borrowed(&name[last_dot_at..]),56 Cow::Owned(ref name) => {57 let mut name = name.clone();58 name.drain_bytes(..last_dot_at);59 Cow::Owned(name)60 }52 Cow::Owned(ref name) => Cow::Owned(name[last_dot_at..].to_vec()),53 })54}5556/// Normalizes a path to use `/` as a separator everywhere, even on platforms
24 unmodified lines
81 use std::borrow::Cow;8283 use bstr::{B, ByteVec};8493 use super::{file_name_ext, normalize_path};85 use super::{file_name, file_name_ext, normalize_path};8687 macro_rules! name {88 ($name:ident, $path:expr, $expected:expr) => {89 #[test]90 fn $name() {91 let bs = Vec::from($path);92 let got = file_name(&Cow::Owned(bs));93 assert_eq!($expected.map(|s| Cow::Borrowed(B(s))), got);94 }95 };96 }9798 name!(name1, "foo/bar", Some("bar"));99 name!(name2, "foo", Some("foo"));100 name!(name3, "foo/..", None::<&str>);101 name!(name4, "", None::<&str>);102103 macro_rules! ext {104 ($name:ident, $file_name:expr, $ext:expr) => {105 #[test]106 fn $name() {
35 unmodified lines