Skip to content

Commit 9561ae6

Browse files
committed
use array instead of vec
1 parent bde6bad commit 9561ae6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/py_string_cache.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,16 @@ const CAPACITY: usize = 65536;
100100

101101
#[derive(Debug)]
102102
struct PyStringCache {
103-
entries: Vec<Option<(u64, Py<PyString>)>>,
103+
entries: [Option<(u64, Py<PyString>)>; CAPACITY],
104104
hash_builder: BuildHasherDefault<AHasher>,
105105
}
106106

107+
const ARRAY_REPEAT_VALUE: Option<(u64, Py<PyString>)> = None;
108+
107109
impl Default for PyStringCache {
108110
fn default() -> Self {
109111
Self {
110-
entries: vec![None; CAPACITY],
112+
entries: [ARRAY_REPEAT_VALUE; CAPACITY],
111113
hash_builder: BuildHasherDefault::default(),
112114
}
113115
}
@@ -159,7 +161,6 @@ impl PyStringCache {
159161

160162
/// clear the cache by resetting all entries to `None`
161163
fn clear(&mut self) {
162-
self.entries.clear();
163-
self.entries.resize(CAPACITY, None);
164+
self.entries = [ARRAY_REPEAT_VALUE; CAPACITY];
164165
}
165166
}

0 commit comments

Comments
 (0)