From 4c154c289e3c18c2517ab8ce91e1d61f45f70388 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 18 Feb 2019 14:13:13 +0300 Subject: remove arena from Roots we want to move ra_vfs to a new repo, so having fewer deps is useful. Arena is a thin layer of sugar on top of Vec anyway. --- crates/ra_vfs/src/lib.rs | 14 +++++++------- crates/ra_vfs/src/roots.rs | 20 +++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs index 7f555a3c0..1c5402aed 100644 --- a/crates/ra_vfs/src/lib.rs +++ b/crates/ra_vfs/src/lib.rs @@ -25,7 +25,7 @@ use std::{ }; 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}; @@ -53,7 +53,7 @@ struct VfsFileData { pub struct Vfs { roots: Arc, files: Arena, - root2files: ArenaMap>, + root2files: FxHashMap>, pending_changes: Vec, worker: Worker, } @@ -72,7 +72,7 @@ impl Vfs { pub fn new(roots: Vec) -> (Vfs, Vec) { 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()); @@ -164,7 +164,7 @@ impl Vfs { 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::>(); @@ -241,7 +241,7 @@ impl Vfs { ) -> 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 } @@ -256,7 +256,7 @@ impl Vfs { 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); } @@ -267,7 +267,7 @@ impl Vfs { } fn find_file(&self, root: VfsRoot, path: &RelativePath) -> Option { - 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) } } diff --git a/crates/ra_vfs/src/roots.rs b/crates/ra_vfs/src/roots.rs index 9d3918502..4503458ee 100644 --- a/crates/ra_vfs/src/roots.rs +++ b/crates/ra_vfs/src/roots.rs @@ -4,12 +4,10 @@ use std::{ }; 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. /// @@ -24,12 +22,12 @@ struct RootData { } pub(crate) struct Roots { - roots: Arena, + roots: Vec, } impl Roots { pub(crate) fn new(mut paths: Vec) -> 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(); @@ -37,7 +35,7 @@ impl Roots { let nested_roots = paths[..i].iter().filter_map(|it| rel_path(path, it)).collect::>(); - roots.alloc(RootData::new(path.clone(), nested_roots)); + roots.push(RootData::new(path.clone(), nested_roots)); } Roots { roots } } @@ -51,20 +49,24 @@ impl Roots { self.roots.len() } pub(crate) fn iter<'a>(&'a self) -> impl Iterator + '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 { - 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 { -- cgit v1.2.3