##// END OF EJS Templates
rust-utils: use new find_dirs iterator...
Raphaël Gomès -
r42814:717686c5 default
parent child Browse files
Show More
@@ -11,6 +11,7 b''
11 11 use std::collections::hash_map::{Entry, Iter};
12 12 use std::collections::HashMap;
13 13 use {DirsIterable, DirstateEntry, DirstateMapError};
14 use utils::files;
14 15
15 16 #[derive(PartialEq, Debug)]
16 17 pub struct DirsMultiset {
@@ -49,40 +50,16 b' impl DirsMultiset {'
49 50 multiset
50 51 }
51 52
52 /// Returns the slice up to the next directory name from right to left,
53 /// without trailing slash
54 fn find_dir(path: &[u8]) -> &[u8] {
55 let mut path = path;
56 loop {
57 if let Some(new_pos) = path.len().checked_sub(1) {
58 if path[new_pos] == b'/' {
59 break &path[..new_pos];
60 }
61 path = &path[..new_pos];
62 } else {
63 break &[];
64 }
65 }
66 }
67
68 53 /// Increases the count of deepest directory contained in the path.
69 54 ///
70 55 /// If the directory is not yet in the map, adds its parents.
71 56 pub fn add_path(&mut self, path: &[u8]) {
72 let mut pos = path.len();
73
74 loop {
75 let subpath = Self::find_dir(&path[..pos]);
57 for subpath in files::find_dirs(path) {
76 58 if let Some(val) = self.inner.get_mut(subpath) {
77 59 *val += 1;
78 60 break;
79 61 }
80 62 self.inner.insert(subpath.to_owned(), 1);
81
82 pos = subpath.len();
83 if pos == 0 {
84 break;
85 }
86 63 }
87 64 }
88 65
@@ -95,10 +72,7 b' impl DirsMultiset {'
95 72 &mut self,
96 73 path: &[u8],
97 74 ) -> Result<(), DirstateMapError> {
98 let mut pos = path.len();
99
100 loop {
101 let subpath = Self::find_dir(&path[..pos]);
75 for subpath in files::find_dirs(path) {
102 76 match self.inner.entry(subpath.to_owned()) {
103 77 Entry::Occupied(mut entry) => {
104 78 let val = entry.get().clone();
@@ -114,11 +88,6 b' impl DirsMultiset {'
114 88 ))
115 89 }
116 90 };
117
118 pos = subpath.len();
119 if pos == 0 {
120 break;
121 }
122 91 }
123 92
124 93 Ok(())
General Comments 0
You need to be logged in to leave comments. Login now