Skip to content

Commit

Permalink
Make new a const fn
Browse files Browse the repository at this point in the history
This removes the initial capacity of `2` and rather makes `new` a `const fn`.
  • Loading branch information
Swatinem authored and Amanieu committed Feb 20, 2024
1 parent 7db3f74 commit bd8410a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ impl<T: Send> Drop for ThreadLocal<T> {

impl<T: Send> ThreadLocal<T> {
/// Creates a new empty `ThreadLocal`.
pub fn new() -> ThreadLocal<T> {
Self::with_capacity(2)
pub const fn new() -> ThreadLocal<T> {
let buckets = [ptr::null_mut::<Entry<T>>(); BUCKETS];
Self {
buckets: unsafe { mem::transmute(buckets) },
values: AtomicUsize::new(0),
}
}

/// Creates a new `ThreadLocal` with an initial capacity. If less than the capacity threads
Expand Down

0 comments on commit bd8410a

Please sign in to comment.