chore: use functional slice building (#8097)

Noticed some redundant procedural code.
This commit is contained in:
Tim Vilgot Mikael Fredenberg
2026-04-30 11:36:55 +02:00
committed by GitHub
parent d3565a2923
commit 26dee92b53
5 changed files with 13 additions and 28 deletions
@@ -90,17 +90,13 @@ fn make_fixed_size<T>(buffer: Box<[T]>) -> Box<[T; LOCAL_QUEUE_CAPACITY]> {
/// Create a new local run-queue
pub(crate) fn local<T: 'static>() -> (Steal<T>, Local<T>) {
let mut buffer = Vec::with_capacity(LOCAL_QUEUE_CAPACITY);
for _ in 0..LOCAL_QUEUE_CAPACITY {
buffer.push(UnsafeCell::new(MaybeUninit::uninit()));
}
let buffer = std::iter::repeat_with(|| UnsafeCell::new(MaybeUninit::uninit()));
let inner = Arc::new(Inner {
head: AtomicUnsignedLong::new(0),
tail: AtomicUnsignedShort::new(0),
lifo: task::AtomicNotified::empty(),
buffer: make_fixed_size(buffer.into_boxed_slice()),
buffer: make_fixed_size(buffer.take(LOCAL_QUEUE_CAPACITY).collect()),
});
let local = Local {
+2 -5
View File
@@ -50,13 +50,10 @@ pub(super) const MAX_DURATION: u64 = (1 << (6 * NUM_LEVELS)) - 1;
impl Wheel {
/// Creates a new timing wheel.
pub(crate) fn new() -> Wheel {
let mut levels = Vec::with_capacity(NUM_LEVELS);
for i in 0..NUM_LEVELS {
levels.push(Level::new(i));
}
let levels = (0..NUM_LEVELS).map(Level::new).collect::<Box<_>>();
Wheel {
elapsed: 0,
levels: levels.into_boxed_slice().try_into().unwrap(),
levels: levels.try_into().unwrap(),
pending: EntryList::new(),
}
}
+2 -5
View File
@@ -39,13 +39,10 @@ pub(super) const MAX_DURATION: u64 = (1 << (6 * NUM_LEVELS)) - 1;
impl Wheel {
/// Creates a new timing wheel.
pub(crate) fn new() -> Wheel {
let mut levels = Vec::with_capacity(NUM_LEVELS);
for i in 0..NUM_LEVELS {
levels.push(Level::new(i));
}
let levels = (0..NUM_LEVELS).map(Level::new).collect::<Box<_>>();
Wheel {
elapsed: 0,
levels: levels.into_boxed_slice().try_into().unwrap(),
levels: levels.try_into().unwrap(),
}
}
+5 -7
View File
@@ -550,18 +550,16 @@ impl<T> Sender<T> {
// Round to a power of two
capacity = capacity.next_power_of_two();
let mut buffer = Vec::with_capacity(capacity);
for i in 0..capacity {
buffer.push(Mutex::new(Slot {
let buffer = (0..capacity).map(|i| {
Mutex::new(Slot {
rem: AtomicUsize::new(0),
pos: (i as u64).wrapping_sub(capacity as u64),
val: None,
}));
}
})
});
let shared = Arc::new(Shared {
buffer: buffer.into_boxed_slice(),
buffer: buffer.collect(),
mask: capacity - 1,
tail: Mutex::new(Tail {
pos: 0,
+2 -5
View File
@@ -38,12 +38,9 @@ impl<L, T> ShardedList<L, T> {
assert!(sharded_size.is_power_of_two());
let shard_mask = sharded_size - 1;
let mut lists = Vec::with_capacity(sharded_size);
for _ in 0..sharded_size {
lists.push(Mutex::new(LinkedList::<L, T>::new()))
}
let lists = std::iter::repeat_with(|| Mutex::new(LinkedList::new()));
Self {
lists: lists.into_boxed_slice(),
lists: lists.take(sharded_size).collect(),
added: MetricAtomicU64::new(0),
count: MetricAtomicUsize::new(0),
shard_mask,