Skip to content

Commit

Permalink
Merge pull request #669 from pkoenig10/as_u128
Browse files Browse the repository at this point in the history
Faster as_u128 and to_u128_le
  • Loading branch information
KodrAus authored Apr 29, 2023
2 parents f725e58 + 7978c5a commit a78ee0a
Showing 1 changed file with 2 additions and 32 deletions.
34 changes: 2 additions & 32 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,22 +687,7 @@ impl Uuid {
/// # }
/// ```
pub const fn as_u128(&self) -> u128 {
(self.as_bytes()[0] as u128) << 120
| (self.as_bytes()[1] as u128) << 112
| (self.as_bytes()[2] as u128) << 104
| (self.as_bytes()[3] as u128) << 96
| (self.as_bytes()[4] as u128) << 88
| (self.as_bytes()[5] as u128) << 80
| (self.as_bytes()[6] as u128) << 72
| (self.as_bytes()[7] as u128) << 64
| (self.as_bytes()[8] as u128) << 56
| (self.as_bytes()[9] as u128) << 48
| (self.as_bytes()[10] as u128) << 40
| (self.as_bytes()[11] as u128) << 32
| (self.as_bytes()[12] as u128) << 24
| (self.as_bytes()[13] as u128) << 16
| (self.as_bytes()[14] as u128) << 8
| (self.as_bytes()[15] as u128)
u128::from_be_bytes(*self.as_bytes())
}

/// Returns a 128bit little-endian value containing the value.
Expand Down Expand Up @@ -731,22 +716,7 @@ impl Uuid {
/// # }
/// ```
pub const fn to_u128_le(&self) -> u128 {
(self.as_bytes()[0] as u128)
| (self.as_bytes()[1] as u128) << 8
| (self.as_bytes()[2] as u128) << 16
| (self.as_bytes()[3] as u128) << 24
| (self.as_bytes()[4] as u128) << 32
| (self.as_bytes()[5] as u128) << 40
| (self.as_bytes()[6] as u128) << 48
| (self.as_bytes()[7] as u128) << 56
| (self.as_bytes()[8] as u128) << 64
| (self.as_bytes()[9] as u128) << 72
| (self.as_bytes()[10] as u128) << 80
| (self.as_bytes()[11] as u128) << 88
| (self.as_bytes()[12] as u128) << 96
| (self.as_bytes()[13] as u128) << 104
| (self.as_bytes()[14] as u128) << 112
| (self.as_bytes()[15] as u128) << 120
u128::from_le_bytes(*self.as_bytes())
}

/// Returns two 64bit values containing the value.
Expand Down

0 comments on commit a78ee0a

Please sign in to comment.