Skip to content

Commit abbde18

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Hide VecMap
Summary: There are certain things I'd want to try, in particular, allocate `RawTable` with entries instead of separate allocation. Public `VecMap` stands in the way. Reviewed By: bobyangyf Differential Revision: D40923063 fbshipit-source-id: 5098c50eaaa65b159dfd4fe8002cd3c51b078f28
1 parent 32b3077 commit abbde18

File tree

4 files changed

+15
-35
lines changed

4 files changed

+15
-35
lines changed

starlark_map/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub mod small_map;
3131
pub mod small_set;
3232
// TODO(nga): make private.
3333
mod iter;
34-
pub mod vec_map;
34+
pub(crate) mod vec_map;
3535

3636
pub use equivalent::Equivalent;
3737
pub use hash_value::StarlarkHashValue;

starlark_map/src/small_map/mod.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -123,26 +123,6 @@ impl<K, V> SmallMap<K, V> {
123123
}
124124
}
125125

126-
#[inline]
127-
pub fn into_raw_parts(self) -> (VecMap<K, V>, Option<Box<RawTable<usize>>>) {
128-
(self.entries, self.index)
129-
}
130-
131-
#[inline]
132-
pub unsafe fn from_raw_parts(
133-
entries: VecMap<K, V>,
134-
index: Option<Box<RawTable<usize>>>,
135-
) -> SmallMap<K, V> {
136-
if let Some(index) = &index {
137-
// Quick smoke test.
138-
// We don't validate indices are correct hence this function is unsafe.
139-
assert!(entries.len() == index.len());
140-
} else {
141-
assert!(entries.len() <= NO_INDEX_THRESHOLD);
142-
}
143-
SmallMap { entries, index }
144-
}
145-
146126
/// Key references iterator.
147127
#[inline]
148128
pub fn keys(&self) -> Keys<K, V> {

starlark_map/src/vec_map/iter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'a, K: 'a, V: 'a> ExactSizeIterator for ValuesMut<'a, K, V> {
109109
}
110110

111111
#[derive(Clone_)]
112-
pub struct Iter<'a, K: 'a, V: 'a> {
112+
pub(crate) struct Iter<'a, K: 'a, V: 'a> {
113113
pub(crate) iter: IterHashed<'a, K, V>,
114114
}
115115

@@ -161,7 +161,7 @@ impl<'a, K: 'a, V: 'a> ExactSizeIterator for IterHashed<'a, K, V> {
161161
}
162162
}
163163

164-
pub struct IterMut<'a, K: 'a, V: 'a> {
164+
pub(crate) struct IterMut<'a, K: 'a, V: 'a> {
165165
pub(crate) iter: std::slice::IterMut<'a, Bucket<K, V>>,
166166
}
167167

@@ -189,7 +189,7 @@ impl<'a, K: 'a, V: 'a> ExactSizeIterator for IterMut<'a, K, V> {
189189
}
190190
}
191191

192-
pub struct IntoIterHashed<K, V> {
192+
pub(crate) struct IntoIterHashed<K, V> {
193193
pub(crate) iter: std::vec::IntoIter<Bucket<K, V>>,
194194
}
195195

@@ -217,7 +217,7 @@ impl<K, V> DoubleEndedIterator for IntoIterHashed<K, V> {
217217
def_double_ended_iter!();
218218
}
219219

220-
pub struct IntoIter<K, V> {
220+
pub(crate) struct IntoIter<K, V> {
221221
pub(crate) iter: IntoIterHashed<K, V>,
222222
}
223223

starlark_map/src/vec_map/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ use gazebo::prelude::*;
2626
use crate::equivalent::Equivalent;
2727
use crate::hash_value::StarlarkHashValue;
2828
use crate::hashed::Hashed;
29-
pub use crate::vec_map::iter::IntoIter;
29+
pub(crate) use crate::vec_map::iter::IntoIter;
3030
pub(crate) use crate::vec_map::iter::IntoIterHashed;
31-
pub use crate::vec_map::iter::Iter;
31+
pub(crate) use crate::vec_map::iter::Iter;
3232
pub(crate) use crate::vec_map::iter::IterHashed;
33-
pub use crate::vec_map::iter::IterMut;
33+
pub(crate) use crate::vec_map::iter::IterMut;
3434
pub(crate) use crate::vec_map::iter::Keys;
3535
pub(crate) use crate::vec_map::iter::Values;
3636
pub(crate) use crate::vec_map::iter::ValuesMut;
@@ -54,20 +54,20 @@ impl<K: Hash, V: Hash> Hash for Bucket<K, V> {
5454
}
5555

5656
#[derive(Debug, Clone, Eq, PartialEq, Default_)]
57-
pub struct VecMap<K, V> {
57+
pub(crate) struct VecMap<K, V> {
5858
buckets: Vec<Bucket<K, V>>,
5959
}
6060

6161
impl<K, V> VecMap<K, V> {
6262
#[inline]
63-
pub const fn new() -> Self {
63+
pub(crate) const fn new() -> Self {
6464
VecMap {
6565
buckets: Vec::new(),
6666
}
6767
}
6868

6969
#[inline]
70-
pub fn with_capacity(n: usize) -> Self {
70+
pub(crate) fn with_capacity(n: usize) -> Self {
7171
VecMap {
7272
buckets: Vec::with_capacity(n),
7373
}
@@ -140,7 +140,7 @@ impl<K, V> VecMap<K, V> {
140140
}
141141

142142
#[inline]
143-
pub fn insert_hashed_unique_unchecked(&mut self, key: Hashed<K>, value: V) {
143+
pub(crate) fn insert_hashed_unique_unchecked(&mut self, key: Hashed<K>, value: V) {
144144
self.buckets.push(Bucket {
145145
hash: key.hash(),
146146
key: key.into_key(),
@@ -173,12 +173,12 @@ impl<K, V> VecMap<K, V> {
173173
}
174174

175175
#[inline]
176-
pub fn len(&self) -> usize {
176+
pub(crate) fn len(&self) -> usize {
177177
self.buckets.len()
178178
}
179179

180180
#[inline]
181-
pub fn is_empty(&self) -> bool {
181+
pub(crate) fn is_empty(&self) -> bool {
182182
self.buckets.is_empty()
183183
}
184184

@@ -226,7 +226,7 @@ impl<K, V> VecMap<K, V> {
226226
}
227227

228228
#[inline]
229-
pub fn into_iter_hashed(self) -> IntoIterHashed<K, V> {
229+
pub(crate) fn into_iter_hashed(self) -> IntoIterHashed<K, V> {
230230
// See the comments on VMIntoIterHash for why this one looks different
231231
IntoIterHashed {
232232
iter: self.buckets.into_iter(),

0 commit comments

Comments
 (0)