about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src/sync/vec.rs
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-03-14 12:11:56 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2023-04-04 09:01:44 +0000
commit46996326377b100fa461b49b5be0c91a075f55e5 (patch)
treea0ace8b18309b85eb4579b8ef7fffd164b29ef29 /compiler/rustc_data_structures/src/sync/vec.rs
parentdaee746771f12f58f707787e8075d9f89ec0511d (diff)
downloadrust-46996326377b100fa461b49b5be0c91a075f55e5.tar.gz
rust-46996326377b100fa461b49b5be0c91a075f55e5.zip
Remove a lock in favor of an AppendOnlyVec
Diffstat (limited to 'compiler/rustc_data_structures/src/sync/vec.rs')
-rw-r--r--compiler/rustc_data_structures/src/sync/vec.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/rustc_data_structures/src/sync/vec.rs b/compiler/rustc_data_structures/src/sync/vec.rs
index 6ffd2a75e81..99de33685f6 100644
--- a/compiler/rustc_data_structures/src/sync/vec.rs
+++ b/compiler/rustc_data_structures/src/sync/vec.rs
@@ -2,6 +2,7 @@ use std::marker::PhantomData;
 
 use rustc_index::vec::Idx;
 
+#[derive(Default)]
 pub struct AppendOnlyIndexVec<I: Idx, T: Copy> {
     #[cfg(not(parallel_compiler))]
     vec: elsa::vec::FrozenVec<T>,
@@ -40,6 +41,7 @@ impl<I: Idx, T: Copy> AppendOnlyIndexVec<I, T> {
     }
 }
 
+#[derive(Default)]
 pub struct AppendOnlyVec<T: Copy> {
     #[cfg(not(parallel_compiler))]
     vec: elsa::vec::FrozenVec<T>,
@@ -57,11 +59,14 @@ impl<T: Copy> AppendOnlyVec<T> {
         }
     }
 
-    pub fn push(&self, val: T) {
+    pub fn push(&self, val: T) -> usize {
+        #[cfg(not(parallel_compiler))]
+        let i = self.vec.len();
         #[cfg(not(parallel_compiler))]
         self.vec.push(val);
         #[cfg(parallel_compiler)]
-        self.vec.push(val)
+        let i = self.vec.push(val);
+        i
     }
 
     pub fn get(&self, i: usize) -> Option<T> {