};
use crossbeam_channel::Receiver;
-use ra_arena::{impl_arena_id, Arena, RawId, map::ArenaMap};
+use ra_arena::{impl_arena_id, Arena, RawId};
use relative_path::{RelativePath, RelativePathBuf};
use rustc_hash::{FxHashMap, FxHashSet};
pub struct Vfs {
roots: Arc<Roots>,
files: Arena<VfsFile, VfsFileData>,
- root2files: ArenaMap<VfsRoot, FxHashSet<VfsFile>>,
+ root2files: FxHashMap<VfsRoot, FxHashSet<VfsFile>>,
pending_changes: Vec<VfsChange>,
worker: Worker,
}
pub fn new(roots: Vec<PathBuf>) -> (Vfs, Vec<VfsRoot>) {
let roots = Arc::new(Roots::new(roots));
let worker = io::start(Arc::clone(&roots));
- let mut root2files = ArenaMap::default();
+ let mut root2files = FxHashMap::default();
for root in roots.iter() {
root2files.insert(root, Default::default());
let mut cur_files = Vec::new();
// While we were scanning the root in the background, a file might have
// been open in the editor, so we need to account for that.
- let existing = self.root2files[root]
+ let existing = self.root2files[&root]
.iter()
.map(|&file| (self.files[file].path.clone(), file))
.collect::<FxHashMap<_, _>>();
) -> VfsFile {
let data = VfsFileData { root, path, text, is_overlayed };
let file = self.files.alloc(data);
- self.root2files.get_mut(root).unwrap().insert(file);
+ self.root2files.get_mut(&root).unwrap().insert(file);
file
}
self.files[file].text = Default::default();
self.files[file].path = Default::default();
let root = self.files[file].root;
- let removed = self.root2files.get_mut(root).unwrap().remove(&file);
+ let removed = self.root2files.get_mut(&root).unwrap().remove(&file);
assert!(removed);
}
}
fn find_file(&self, root: VfsRoot, path: &RelativePath) -> Option<VfsFile> {
- self.root2files[root].iter().map(|&it| it).find(|&file| self.files[file].path == path)
+ self.root2files[&root].iter().map(|&it| it).find(|&file| self.files[file].path == path)
}
}
};
use relative_path::{ RelativePath, RelativePathBuf};
-use ra_arena::{impl_arena_id, Arena, RawId};
/// VfsRoot identifies a watched directory on the file system.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
-pub struct VfsRoot(pub RawId);
-impl_arena_id!(VfsRoot);
+pub struct VfsRoot(pub u32);
/// Describes the contents of a single source root.
///
}
pub(crate) struct Roots {
- roots: Arena<VfsRoot, RootData>,
+ roots: Vec<RootData>,
}
impl Roots {
pub(crate) fn new(mut paths: Vec<PathBuf>) -> Roots {
- let mut roots = Arena::default();
+ let mut roots = Vec::new();
// A hack to make nesting work.
paths.sort_by_key(|it| std::cmp::Reverse(it.as_os_str().len()));
paths.dedup();
let nested_roots =
paths[..i].iter().filter_map(|it| rel_path(path, it)).collect::<Vec<_>>();
- roots.alloc(RootData::new(path.clone(), nested_roots));
+ roots.push(RootData::new(path.clone(), nested_roots));
}
Roots { roots }
}
self.roots.len()
}
pub(crate) fn iter<'a>(&'a self) -> impl Iterator<Item = VfsRoot> + 'a {
- self.roots.iter().map(|(id, _)| id)
+ (0..self.roots.len()).into_iter().map(|idx| VfsRoot(idx as u32))
}
pub(crate) fn path(&self, root: VfsRoot) -> &Path {
- self.roots[root].path.as_path()
+ self.root(root).path.as_path()
}
/// Checks if root contains a path and returns a root-relative path.
pub(crate) fn contains(&self, root: VfsRoot, path: &Path) -> Option<RelativePathBuf> {
- let data = &self.roots[root];
+ let data = self.root(root);
iter::once(&data.path)
.chain(data.canonical_path.as_ref().into_iter())
.find_map(|base| rel_path(base, path))
.filter(|path| !data.excluded_dirs.contains(path))
.filter(|path| !data.is_excluded(path))
}
+
+ fn root(&self, root: VfsRoot) -> &RootData {
+ &self.roots[root.0 as usize]
+ }
}
impl RootData {