Skip to content

Commit

Permalink
Merge pull request #1546 from waywardmonkeys/use-ux-from-bool
Browse files Browse the repository at this point in the history
Use u8::from(bool), u64::from(bool).
  • Loading branch information
PSeitz authored Sep 23, 2022
2 parents fa3d786 + e9a384b commit f9c3947
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 17 deletions.
12 changes: 2 additions & 10 deletions common/src/bitset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,7 @@ impl BitSet {
// we do not check saturated els.
let higher = el / 64u32;
let lower = el % 64u32;
self.len += if self.tinysets[higher as usize].insert_mut(lower) {
1
} else {
0
};
self.len += u64::from(self.tinysets[higher as usize].insert_mut(lower));
}

/// Inserts an element in the `BitSet`
Expand All @@ -272,11 +268,7 @@ impl BitSet {
// we do not check saturated els.
let higher = el / 64u32;
let lower = el % 64u32;
self.len -= if self.tinysets[higher as usize].remove_mut(lower) {
1
} else {
0
};
self.len -= u64::from(self.tinysets[higher as usize].remove_mut(lower));
}

/// Returns true iff the elements is in the `BitSet`.
Expand Down
3 changes: 1 addition & 2 deletions common/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ impl FixedSize for u8 {

impl BinarySerializable for bool {
fn serialize<W: Write>(&self, writer: &mut W) -> io::Result<()> {
let val = if *self { 1 } else { 0 };
writer.write_u8(val)
writer.write_u8(u8::from(*self))
}
fn deserialize<R: Read>(reader: &mut R) -> io::Result<bool> {
let val = reader.read_u8()?;
Expand Down
6 changes: 1 addition & 5 deletions fastfield_codecs/src/monotonic_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ impl MonotonicallyMappableToU64 for i64 {
impl MonotonicallyMappableToU64 for bool {
#[inline(always)]
fn to_u64(self) -> u64 {
if self {
1
} else {
0
}
u64::from(self)
}

#[inline(always)]
Expand Down

0 comments on commit f9c3947

Please sign in to comment.