Skip to content

Commit

Permalink
Revert "Change the type of positions and add positions() (#47)" (#49
Browse files Browse the repository at this point in the history
)

This reverts commit e29f2ef.

I found out `positions()` doesn't have to be exposed to the caller of `MatchedPath`.
  • Loading branch information
yykamei authored May 29, 2021
1 parent e29f2ef commit 7509014
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/matched_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fmt::{self, Display, Formatter};
pub(crate) struct MatchedPath {
absolute: String,
relative: String,
positions: Vec<usize>,
positions: VecDeque<usize>,
depth: usize,
}

Expand All @@ -29,11 +29,6 @@ impl MatchedPath {
&self.relative
}

#[allow(dead_code)] // TODO: Use it later
pub(crate) fn positions(&self) -> &[usize] {
self.positions.as_slice()
}

/// Calculate the total distance between each position.
/// For example, if the `positions` is `vec![1, 2, 3]`, then the distance will be `2`.
/// If the `positions` is `vec![1, 4, 5]`, then the distance will be `4`.
Expand Down Expand Up @@ -106,7 +101,7 @@ fn depth_from<'a>(relative: impl Iterator<Item = &'a char>) -> usize {

/// Calculates matched positions of `relative` with `query`.
/// This searches for characters of `query` in `relative` from the right one by one.
fn positions_from(query: &str, relative: &[char]) -> Option<Vec<usize>> {
fn positions_from(query: &str, relative: &[char]) -> Option<VecDeque<usize>> {
let mut positions: VecDeque<usize> = VecDeque::with_capacity(query.len());
for char in normalize_query(query).chars().rev() {
let end = if let Some(pos) = positions.front() {
Expand All @@ -118,7 +113,7 @@ fn positions_from(query: &str, relative: &[char]) -> Option<Vec<usize>> {
let pos = target.iter().rposition(|t| char.eq_ignore_ascii_case(t))?;
positions.push_front(pos);
}
Some(Vec::from(positions))
Some(positions)
}

#[cfg(target_os = "windows")]
Expand Down Expand Up @@ -148,7 +143,7 @@ mod tests {
MatchedPath {
absolute: String::from("/abc/abc/abc.txt"),
relative: String::from("abc/abc/abc.txt"),
positions: vec![8, 9, 10, 11, 12, 13, 14],
positions: VecDeque::from(vec![8, 9, 10, 11, 12, 13, 14]),
depth: 2,
},
);
Expand All @@ -157,7 +152,7 @@ mod tests {
MatchedPath {
absolute: String::from("/abc/abc/abc.txt"),
relative: String::from("abc/abc/abc.txt"),
positions: vec![8, 9, 10],
positions: VecDeque::from(vec![8, 9, 10]),
depth: 2,
},
);
Expand All @@ -170,7 +165,7 @@ mod tests {
MatchedPath {
absolute: String::from("C:\\Documents\\Newsletters\\Summer2018.pdf"),
relative: String::from("Newsletters\\Summer2018.pdf"),
positions: vec![7, 8, 15],
positions: VecDeque::from(vec![7, 8, 15]),
depth: 1,
},
);
Expand All @@ -179,7 +174,7 @@ mod tests {
MatchedPath {
absolute: String::from("\\Folder\\foo\\bar\\☕.txt"),
relative: String::from("foo\\bar\\☕.txt"),
positions: vec![0, 1, 2, 8, 12],
positions: VecDeque::from(vec![0, 1, 2, 8, 12]),
depth: 2,
},
);
Expand All @@ -189,7 +184,6 @@ mod tests {
fn returns_fields() {
let path = new("abc", "/home", "/home/abc.txt");
assert_eq!(path.relative(), "abc.txt");
assert_eq!(path.positions(), vec![0, 1, 2]);
}

#[test]
Expand Down

0 comments on commit 7509014

Please sign in to comment.