Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace bitvec with fixedbitset #191

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ harness = false
[features]
default = ["std"]
std = ["alloc"]
alloc = ["bitvec/alloc", "dep:slab", "dep:smallvec"]
alloc = ["dep:fixedbitset", "dep:slab", "dep:smallvec"]

[dependencies]
bitvec = { version = "1.0.1", default-features = false, features = ["alloc"] }
fixedbitset = { version = "0.5.7", default-features = false, optional = true }
futures-core = { version = "0.3", default-features = false }
futures-lite = "1.12.0"
pin-project = "1.0.8"
Expand Down
34 changes: 27 additions & 7 deletions src/utils/wakers/vec/readiness_vec.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use bitvec::{bitvec, vec::BitVec};
use core::task::Waker;
use fixedbitset::FixedBitSet;

/// Tracks which wakers are "ready" and should be polled.
#[derive(Debug)]
pub(crate) struct ReadinessVec {
ready_count: usize,
max_count: usize,
readiness_list: BitVec,
readiness_list: FixedBitSet,
parent_waker: Option<Waker>,
}

Expand All @@ -16,7 +16,8 @@ impl ReadinessVec {
Self {
ready_count: len,
max_count: len,
readiness_list: bitvec![true as usize; len],
// See https://github.com/petgraph/fixedbitset/issues/101
readiness_list: FixedBitSet::with_capacity_and_blocks(len, std::iter::repeat(!0)),
parent_waker: None,
}
}
Expand All @@ -36,7 +37,7 @@ impl ReadinessVec {

/// Set all markers to ready.
pub(crate) fn set_all_ready(&mut self) {
self.readiness_list.fill(true);
self.readiness_list.set_range(.., true);
self.ready_count = self.max_count;
}

Expand All @@ -56,7 +57,7 @@ impl ReadinessVec {
/// Returns whether the task id was previously ready
#[allow(unused)]
pub(crate) fn clear_all_ready(&mut self) {
self.readiness_list.fill(false);
self.readiness_list.set_range(.., false);
self.ready_count = 0;
}

Expand Down Expand Up @@ -85,8 +86,27 @@ impl ReadinessVec {
/// If new entries are created, they will be marked as 'ready'.
pub(crate) fn resize(&mut self, len: usize) {
self.max_count = len;
self.readiness_list.resize(len, true);
self.ready_count = self.readiness_list.iter_ones().count();

let old_len = self.readiness_list.len();
match len.cmp(&old_len) {
std::cmp::Ordering::Less => {
yoshuawuyts marked this conversation as resolved.
Show resolved Hide resolved
// shrink
self.ready_count -= self.readiness_list.count_ones(len..);
self.readiness_list = FixedBitSet::with_capacity_and_blocks(
len,
self.readiness_list.as_slice().iter().cloned(),
);
}
std::cmp::Ordering::Equal => {
// no-op
}
std::cmp::Ordering::Greater => {
// grow
self.readiness_list.grow(len);
self.readiness_list.set_range(old_len..len, true);
self.ready_count += len - old_len;
}
}
}
}

Expand Down
Loading