Skip to content

Commit

Permalink
libstd: Inline more methods on bitflags.
Browse files Browse the repository at this point in the history
Servo really wants this.
  • Loading branch information
pcwalton committed Oct 16, 2014
1 parent 9d5fa7a commit 416e6ec
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libstd/bitflags.rs
Expand Up @@ -127,22 +127,26 @@ macro_rules! bitflags {

impl $BitFlags {
/// Returns an empty set of flags.
#[inline]
pub fn empty() -> $BitFlags {
$BitFlags { bits: 0 }
}

/// Returns the set containing all flags.
#[inline]
pub fn all() -> $BitFlags {
$BitFlags { bits: $($value)|+ }
}

/// Returns the raw value of the flags currently stored.
#[inline]
pub fn bits(&self) -> $T {
self.bits
}

/// Convert from underlying bit representation, unless that
/// representation contains bits that do not correspond to a flag.
#[inline]
pub fn from_bits(bits: $T) -> ::std::option::Option<$BitFlags> {
if (bits & !$BitFlags::all().bits()) != 0 {
::std::option::None
Expand All @@ -153,21 +157,25 @@ macro_rules! bitflags {

/// Convert from underlying bit representation, dropping any bits
/// that do not correspond to flags.
#[inline]
pub fn from_bits_truncate(bits: $T) -> $BitFlags {
$BitFlags { bits: bits } & $BitFlags::all()
}

/// Returns `true` if no flags are currently stored.
#[inline]
pub fn is_empty(&self) -> bool {
*self == $BitFlags::empty()
}

/// Returns `true` if all flags are currently set.
#[inline]
pub fn is_all(&self) -> bool {
*self == $BitFlags::all()
}

/// Returns `true` if there are flags common to both `self` and `other`.
#[inline]
pub fn intersects(&self, other: $BitFlags) -> bool {
!(self & other).is_empty()
}
Expand All @@ -179,16 +187,19 @@ macro_rules! bitflags {
}

/// Inserts the specified flags in-place.
#[inline]
pub fn insert(&mut self, other: $BitFlags) {
self.bits |= other.bits;
}

/// Removes the specified flags in-place.
#[inline]
pub fn remove(&mut self, other: $BitFlags) {
self.bits &= !other.bits;
}

/// Toggles the specified flags in-place.
#[inline]
pub fn toggle(&mut self, other: $BitFlags) {
self.bits ^= other.bits;
}
Expand Down

5 comments on commit 416e6ec

@bors
Copy link
Contributor

@bors bors commented on 416e6ec Oct 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at pcwalton@416e6ec

@bors
Copy link
Contributor

@bors bors commented on 416e6ec Oct 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pcwalton/rust/bitflags-inline = 416e6ec into auto

@bors
Copy link
Contributor

@bors bors commented on 416e6ec Oct 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pcwalton/rust/bitflags-inline = 416e6ec merged ok, testing candidate = c7c342d

@bors
Copy link
Contributor

@bors bors commented on 416e6ec Oct 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 416e6ec Oct 18, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = c7c342d

Please sign in to comment.