Skip to content

Commit

Permalink
reduce bitshifts in from_u64_pair
Browse files Browse the repository at this point in the history
  • Loading branch information
KodrAus committed Jan 19, 2025
1 parent 4c785e5 commit cfc627b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
23 changes: 23 additions & 0 deletions benches/new.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![feature(test)]
extern crate test;

use test::Bencher;
use uuid::Uuid;

#[bench]
fn from_bytes(b: &mut Bencher) {
b.iter(|| Uuid::from_bytes([
0xF9, 0x16, 0x8C, 0x5E, 0xCE, 0xB2, 0x4F, 0xAA, 0xB6, 0xBF, 0x32, 0x9B, 0xF3, 0x9F,
0xA1, 0xE4,
]));
}

#[bench]
fn from_u128(b: &mut Bencher) {
b.iter(|| Uuid::from_u128(0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8));
}

#[bench]
fn from_u64_pair(b: &mut Bencher) {
b.iter(|| Uuid::from_u64_pair(0xa1a2a3a4b1b2c1c2, 0xd1d2d3d4d5d6d7d8));
}
19 changes: 1 addition & 18 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,24 +252,7 @@ impl Uuid {
/// );
/// ```
pub const fn from_u64_pair(high_bits: u64, low_bits: u64) -> Self {
Uuid::from_bytes([
(high_bits >> 56) as u8,
(high_bits >> 48) as u8,
(high_bits >> 40) as u8,
(high_bits >> 32) as u8,
(high_bits >> 24) as u8,
(high_bits >> 16) as u8,
(high_bits >> 8) as u8,
high_bits as u8,
(low_bits >> 56) as u8,
(low_bits >> 48) as u8,
(low_bits >> 40) as u8,
(low_bits >> 32) as u8,
(low_bits >> 24) as u8,
(low_bits >> 16) as u8,
(low_bits >> 8) as u8,
low_bits as u8,
])
Uuid::from_u128((high_bits as u128 << 64) | low_bits as u128)
}

/// Creates a UUID using the supplied bytes.
Expand Down

0 comments on commit cfc627b

Please sign in to comment.