]> git.lizzy.rs Git - rust.git/commitdiff
remove arena from Roots
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 18 Feb 2019 11:13:13 +0000 (14:13 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 18 Feb 2019 11:13:13 +0000 (14:13 +0300)
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
crates/ra_vfs/src/roots.rs

index 7f555a3c009cc4bc156e2155c6ca443888b023ed..1c5402aed94ed8742066e8610ebbfea0483dd9be 100644 (file)
@@ -25,7 +25,7 @@
 };
 
 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<Roots>,
     files: Arena<VfsFile, VfsFileData>,
-    root2files: ArenaMap<VfsRoot, FxHashSet<VfsFile>>,
+    root2files: FxHashMap<VfsRoot, FxHashSet<VfsFile>>,
     pending_changes: Vec<VfsChange>,
     worker: Worker,
 }
@@ -72,7 +72,7 @@ impl Vfs {
     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());
@@ -164,7 +164,7 @@ pub fn handle_task(&mut self, task: io::TaskResult) {
                 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<_, _>>();
@@ -241,7 +241,7 @@ fn raw_add_file(
     ) -> 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 @@ fn raw_remove_file(&mut self, file: VfsFile) {
         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 @@ fn find_root(&self, path: &Path) -> Option<(VfsRoot, RelativePathBuf, Option<Vfs
     }
 
     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)
     }
 }
 
index 9d3918502c44c119e4461edc945245757ddd62db..4503458eed173e62513a180a3e96edf607046ee6 100644 (file)
@@ -4,12 +4,10 @@
 };
 
 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<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();
@@ -37,7 +35,7 @@ pub(crate) fn new(mut paths: Vec<PathBuf>) -> Roots {
             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 }
     }
@@ -51,20 +49,24 @@ pub(crate) fn len(&self) -> usize {
         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 {