cleanup EventMask
This commit is contained in:
parent
2d7ba44621
commit
582a15a693
1 changed files with 9 additions and 9 deletions
|
@ -331,34 +331,34 @@ impl Message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const EVENT_BITS: usize = ((Event::LAST as usize + 31) & !31) / 32;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct EventMask {
|
struct EventMask {
|
||||||
mask: [u32; EVENT_BITS],
|
mask: [u32; Self::WORD_COUNT],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventMask {
|
impl EventMask {
|
||||||
|
const WORD_COUNT: usize = ((Event::LAST as u32 + (u32::BITS - 1)) / u32::BITS) as usize;
|
||||||
|
|
||||||
fn enable(&mut self, event: Event) {
|
fn enable(&mut self, event: Event) {
|
||||||
let n = event as u32;
|
let n = event as u32;
|
||||||
let word = n >> 5;
|
let word = n / u32::BITS;
|
||||||
let bit = n & 0b11111;
|
let bit = n % u32::BITS;
|
||||||
|
|
||||||
self.mask[word as usize] |= (1 << bit);
|
self.mask[word as usize] |= (1 << bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable(&mut self, event: Event) {
|
fn disable(&mut self, event: Event) {
|
||||||
let n = event as u32;
|
let n = event as u32;
|
||||||
let word = n >> 5;
|
let word = n / u32::BITS;
|
||||||
let bit = n & 0b11111;
|
let bit = n % u32::BITS;
|
||||||
|
|
||||||
self.mask[word as usize] &= !(1 << bit);
|
self.mask[word as usize] &= !(1 << bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_enabled(&self, event: Event) -> bool {
|
fn is_enabled(&self, event: Event) -> bool {
|
||||||
let n = event as u32;
|
let n = event as u32;
|
||||||
let word = n >> 5;
|
let word = n / u32::BITS;
|
||||||
let bit = n & 0b11111;
|
let bit = n % u32::BITS;
|
||||||
|
|
||||||
self.mask[word as usize] & (1 << bit) > 0
|
self.mask[word as usize] & (1 << bit) > 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue