Skip to content

Commit a3f1f78

Browse files
committed
Avoid calling InternalBitFlags::{bits,from_bits_retain}.
It's simpler to just use `Self()` and `.0`. Here's an example of how that changes the output for one method: ``` pub const fn union(self, other: Self) -> Self { - Self::from_bits_retain(self.bits() | other.bits()) + Self(self.0 | other.0) } ``` As well as being simpler, this change makes the code a tiny bit faster to compile, and results in much better code quality (no function calls) in dev builds.
1 parent aead794 commit a3f1f78

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

src/public.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ macro_rules! __impl_public_bitflags {
164164
)*
165165

166166
let _ = i;
167-
Self::from_bits_retain(truncated)
167+
Self(truncated)
168168
}
169169

170170
fn bits(&self) {
@@ -182,7 +182,7 @@ macro_rules! __impl_public_bitflags {
182182
}
183183

184184
fn from_bits_truncate(bits) {
185-
Self(bits & Self::all().bits())
185+
Self(bits & Self::all().0)
186186
}
187187

188188
fn from_bits_retain(bits) {
@@ -212,33 +212,33 @@ macro_rules! __impl_public_bitflags {
212212
}
213213

214214
fn is_empty(&self) {
215-
self.bits() == <$T as $crate::Bits>::EMPTY
215+
self.0 == <$T as $crate::Bits>::EMPTY
216216
}
217217

218218
fn is_all(&self) {
219219
// NOTE: We check against `Self::all` here, not `Self::Bits::ALL`
220220
// because the set of all flags may not use all bits
221-
Self::all().bits() | self.bits() == self.bits()
221+
Self::all().0 | self.0 == self.0
222222
}
223223

224224
fn intersects(&self, other) {
225-
self.bits() & other.bits() != <$T as $crate::Bits>::EMPTY
225+
self.0 & other.0 != <$T as $crate::Bits>::EMPTY
226226
}
227227

228228
fn contains(&self, other) {
229-
self.bits() & other.bits() == other.bits()
229+
self.0 & other.0 == other.0
230230
}
231231

232232
fn insert(&mut self, other) {
233-
*self = Self::from_bits_retain(self.bits()).union(other);
233+
*self = Self(self.0).union(other);
234234
}
235235

236236
fn remove(&mut self, other) {
237-
*self = Self::from_bits_retain(self.bits()).difference(other);
237+
*self = Self(self.0).difference(other);
238238
}
239239

240240
fn toggle(&mut self, other) {
241-
*self = Self::from_bits_retain(self.bits()).symmetric_difference(other);
241+
*self = Self(self.0).symmetric_difference(other);
242242
}
243243

244244
fn set(&mut self, other, value) {
@@ -250,23 +250,23 @@ macro_rules! __impl_public_bitflags {
250250
}
251251

252252
fn intersection(self, other) {
253-
Self::from_bits_retain(self.bits() & other.bits())
253+
Self(self.0 & other.0)
254254
}
255255

256256
fn union(self, other) {
257-
Self::from_bits_retain(self.bits() | other.bits())
257+
Self(self.0 | other.0)
258258
}
259259

260260
fn difference(self, other) {
261-
Self::from_bits_retain(self.bits() & !other.bits())
261+
Self(self.0 & !other.0)
262262
}
263263

264264
fn symmetric_difference(self, other) {
265-
Self::from_bits_retain(self.bits() ^ other.bits())
265+
Self(self.0 ^ other.0)
266266
}
267267

268268
fn complement(self) {
269-
Self::from_bits_truncate(!self.bits())
269+
Self::from_bits_truncate(!self.0)
270270
}
271271
}
272272
}

0 commit comments

Comments
 (0)