Skip to content

Commit a1b2c83

Browse files
committed
Removes unsafe vector allocators
Note to self: before merging this, we should do a bit more benchmarking to see how this actually affects perf. From #163, it seems negligble.
1 parent af21705 commit a1b2c83

File tree

3 files changed

+5
-28
lines changed

3 files changed

+5
-28
lines changed

src/backing_store/bump_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A unique table based on a bump allocator and robin-hood hashing
22
//! this is the primary unique table for storing all nodes
33
4-
use crate::{backing_store::UniqueTable, util::*};
4+
use crate::backing_store::UniqueTable;
55
use bumpalo::Bump;
66
use rustc_hash::FxHasher;
77
use std::{
@@ -105,7 +105,7 @@ where
105105
{
106106
/// reserve a robin-hood table capable of holding at least `sz` elements
107107
pub fn new() -> BackedRobinhoodTable<'a, T> {
108-
let v: Vec<HashTableElement<T>> = zero_vec(DEFAULT_SIZE);
108+
let v: Vec<HashTableElement<T>> = vec![HashTableElement::default(); DEFAULT_SIZE];
109109

110110
BackedRobinhoodTable {
111111
tbl: v,
@@ -135,7 +135,7 @@ where
135135
pub fn grow(&mut self) {
136136
let new_sz = (self.cap + 1).next_power_of_two();
137137
self.cap = new_sz;
138-
let old = mem::replace(&mut self.tbl, zero_vec(new_sz));
138+
let old = mem::replace(&mut self.tbl, vec![HashTableElement::default(); new_sz]);
139139
let c = self.cap;
140140
for i in old.iter() {
141141
propagate(&mut self.tbl, self.cap, i.clone(), (i.hash as usize) % c);

src/repr/var_order.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! in the order occur first in the BDD, starting from the root.
33
//! Lower numbers occur first in the order (i.e., closer to the root)
44
5-
use crate::{repr::var_label::VarLabel, util};
5+
use crate::repr::var_label::VarLabel;
66
use std::fmt::{Debug, Display};
77

88
#[derive(Debug, Clone)]
@@ -19,7 +19,7 @@ impl VarOrder {
1919
/// Creates a new variable order (elements that occur first in the vector
2020
/// occur first in the order)
2121
pub fn new(order: Vec<VarLabel>) -> VarOrder {
22-
let mut v = util::malloc_vec(order.len());
22+
let mut v = vec![0; order.len()];
2323
let mut pos_to_var = Vec::new();
2424
for i in 0..order.len() {
2525
v[order[i].value() as usize] = i;

src/util/mod.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ pub mod hypergraph;
55
pub mod lru;
66
pub mod semirings;
77

8-
use std::ptr;
9-
108
/// A generic bit-field which makes it easier to get and set
119
/// bit-level fields
1210
#[macro_export]
@@ -30,24 +28,3 @@ macro_rules! BITFIELD {
3028
)+}
3129
}
3230
}
33-
34-
/// custom allocations for zeroed vectors
35-
pub fn zero_vec<T>(sz: usize) -> Vec<T> {
36-
let mut v: Vec<T> = Vec::with_capacity(sz);
37-
unsafe {
38-
let vec_ptr = v.as_mut_ptr();
39-
ptr::write_bytes(vec_ptr, 0, sz);
40-
v.set_len(sz);
41-
}
42-
v
43-
}
44-
45-
/// custom allocation of a non-initialized vector
46-
#[allow(clippy::uninit_vec)] // intentional!
47-
pub fn malloc_vec<T>(sz: usize) -> Vec<T> {
48-
let mut v: Vec<T> = Vec::with_capacity(sz);
49-
unsafe {
50-
v.set_len(sz);
51-
}
52-
v
53-
}

0 commit comments

Comments
 (0)