Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #545 from KodrAus/feat/fast-rng
Add support for using rand for rng
- Loading branch information
Showing
7 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![cfg(feature = "v4")] | ||
|
||
#![feature(test)] | ||
extern crate test; | ||
|
||
use test::Bencher; | ||
use uuid::Uuid; | ||
|
||
#[bench] | ||
fn new_v4(b: &mut Bencher) { | ||
b.iter(|| Uuid::new_v4()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#[cfg(feature = "v4")] | ||
pub(crate) fn bytes() -> [u8; 16] { | ||
#[cfg(not(feature = "fast-rng"))] | ||
{ | ||
let mut bytes = [0u8; 16]; | ||
|
||
getrandom::getrandom(&mut bytes).unwrap_or_else(|err| { | ||
// NB: getrandom::Error has no source; this is adequate display | ||
panic!("could not retrieve random bytes for uuid: {}", err) | ||
}); | ||
|
||
bytes | ||
} | ||
|
||
#[cfg(feature = "fast-rng")] | ||
{ | ||
use rand::RngCore; | ||
let mut rng = rand::thread_rng(); | ||
|
||
let mut bytes = [0u8; 16]; | ||
rng.fill_bytes(&mut bytes); | ||
|
||
bytes | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters