Bug 1817900 - Update fastrand to 1.9.0. r=emilio,supply-chain-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D170434
This commit is contained in:
Mike Hommey 2023-02-23 01:12:49 +00:00
Родитель 7fa4b01ea2
Коммит 7f34181fc9
8 изменённых файлов: 85 добавлений и 23 удалений

4
Cargo.lock сгенерированный
Просмотреть файл

@ -1670,9 +1670,9 @@ dependencies = [
[[package]]
name = "fastrand"
version = "1.8.0"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be"
dependencies = [
"instant",
]

Просмотреть файл

@ -726,6 +726,11 @@ who = "Mike Hommey <mh+mozilla@glandium.org>"
criteria = "safe-to-deploy"
delta = "1.7.0 -> 1.8.0"
[[audits.fastrand]]
who = "Mike Hommey <mh+mozilla@glandium.org>"
criteria = "safe-to-deploy"
delta = "1.8.0 -> 1.9.0"
[[audits.filetime_win]]
who = "Nick Alexander <nalexander@mozilla.com>"
criteria = "safe-to-deploy"

Просмотреть файл

@ -1 +1 @@
{"files":{"CHANGELOG.md":"b424a8fc1905344cc5044f51c970390a6420d05e1b58168b1f5bd8fa14b4a9b9","Cargo.toml":"8c350aabe8464b4c8f26f861dfa05cefb61316d13b649ce7ab9393d2bcc9595f","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"dec6b96d3549746937d7e0e62e35e206e6f5b7e2d1886451281905f4edf096d4","benches/bench.rs":"8a8a38a032c4b0442aeccfeb5444e6824ad5e50143c9feec88803d6558312232","src/lib.rs":"94a02ae3d22d55a792b5c5739183039644830c4d1c9a3399c8c7570e0f043ada","tests/char.rs":"a530b41837f5bf43701d983ef0267d9b44779d455f24cbf30b881cd348de9ee1","tests/smoke.rs":"10631fa1facee3243e12a8fc56856f2bddfc7090be17b3364edbbac9973692d9"},"package":"a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"}
{"files":{"CHANGELOG.md":"64192695962b6d2ec5f1f57f3b7909c216611a5de5cd5d0d28d863477eef0a12","Cargo.toml":"9d3bf85fff7d7228a8aae6e0c20a43f19a846412e598ee0b7d1f6f2a30bac880","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"23f18e03dc49df91622fe2a76176497404e46ced8a715d9d2b67a7446571cca3","README.md":"dec6b96d3549746937d7e0e62e35e206e6f5b7e2d1886451281905f4edf096d4","benches/bench.rs":"234b2e5f725102ed0ff7686def089de23e433eeecaf03542af31fc60725e85e3","src/lib.rs":"88bf8a952c723b28b989c7b998b2ec0de6a1351f6891088d6237300c8982f36d","tests/char.rs":"a530b41837f5bf43701d983ef0267d9b44779d455f24cbf30b881cd348de9ee1","tests/smoke.rs":"aac00322cce06f15378aacbf247a37e9602c46cfd2bd588a0887b266cbc4770a"},"package":"e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be"}

5
third_party/rust/fastrand/CHANGELOG.md поставляемый
Просмотреть файл

@ -1,3 +1,8 @@
# Version 1.9.0
- Add `Rng::fill()` (#35, #43)
- Add `#[must_use]` to `Rng::with_seed()` (#46)
# Version 1.8.0
- Add `get_seed()` and `Rng::get_seed()` (#33)

10
third_party/rust/fastrand/Cargo.toml поставляемый
Просмотреть файл

@ -13,7 +13,7 @@
edition = "2018"
rust-version = "1.34"
name = "fastrand"
version = "1.8.0"
version = "1.9.0"
authors = ["Stjepan Glavina <stjepang@gmail.com>"]
exclude = ["/.*"]
description = "A simple and fast random number generator"
@ -38,16 +38,16 @@ version = "0.8"
[dev-dependencies.wyhash]
version = "0.5"
[target."cfg(target_arch = \"wasm32\")".dependencies.instant]
[target."cfg(all(target_arch = \"wasm32\", not(target_os = \"wasi\")))".dependencies.instant]
version = "0.1"
[target."cfg(target_arch = \"wasm32\")".dev-dependencies.getrandom]
[target."cfg(all(target_arch = \"wasm32\", not(target_os = \"wasi\")))".dev-dependencies.getrandom]
version = "0.2"
features = ["js"]
[target."cfg(target_arch = \"wasm32\")".dev-dependencies.instant]
[target."cfg(all(target_arch = \"wasm32\", not(target_os = \"wasi\")))".dev-dependencies.instant]
version = "0.1"
features = ["wasm-bindgen"]
[target."cfg(target_arch = \"wasm32\")".dev-dependencies.wasm-bindgen-test]
[target."cfg(all(target_arch = \"wasm32\", not(target_os = \"wasi\")))".dev-dependencies.wasm-bindgen-test]
version = "0.3"

23
third_party/rust/fastrand/benches/bench.rs поставляемый
Просмотреть файл

@ -73,3 +73,26 @@ fn u32_fastrand(b: &mut Bencher) {
sum
})
}
#[bench]
fn fill(b: &mut Bencher) {
let rng = fastrand::Rng::new();
b.iter(|| {
// Pick a size that isn't divisble by 8.
let mut bytes = [0u8; 367];
rng.fill(&mut bytes);
bytes
})
}
#[bench]
fn fill_naive(b: &mut Bencher) {
let rng = fastrand::Rng::new();
b.iter(|| {
let mut bytes = [0u8; 367];
for item in &mut bytes {
*item = rng.u8(..);
}
bytes
})
}

32
third_party/rust/fastrand/src/lib.rs поставляемый
Просмотреть файл

@ -70,13 +70,14 @@
use std::cell::Cell;
use std::collections::hash_map::DefaultHasher;
use std::convert::TryInto;
use std::hash::{Hash, Hasher};
use std::ops::{Bound, RangeBounds};
use std::thread;
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
use instant::Instant;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))]
use std::time::Instant;
/// A random number generator.
@ -281,6 +282,7 @@ impl Rng {
/// Creates a new random number generator with the initial seed.
#[inline]
#[must_use = "this creates a new instance of `Rng`; if you want to initialize the thread-local generator, use `fastrand::seed()` instead"]
pub fn with_seed(seed: u64) -> Self {
let rng = Rng(Cell::new(0));
@ -441,6 +443,30 @@ impl Rng {
}
}
/// Fill a byte slice with random data.
#[inline]
pub fn fill(&self, slice: &mut [u8]) {
// We fill the slice by chunks of 8 bytes, or one block of
// WyRand output per new state.
let mut chunks = slice.chunks_exact_mut(core::mem::size_of::<u64>());
for chunk in chunks.by_ref() {
let n = self.gen_u64().to_ne_bytes();
// Safe because the chunks are always 8 bytes exactly.
chunk.copy_from_slice(&n);
}
let remainder = chunks.into_remainder();
// Any remainder will always be less than 8 bytes.
if !remainder.is_empty() {
// Generate one last block of 8 bytes of entropy
let n = self.gen_u64().to_ne_bytes();
// Use the remaining length to copy from block
remainder.copy_from_slice(&n[..remainder.len()]);
}
}
rng_integer!(
u8,
u8,
@ -528,7 +554,7 @@ impl Rng {
/// Panics if the range is empty.
#[inline]
pub fn char(&self, range: impl RangeBounds<char>) -> char {
use std::convert::{TryFrom, TryInto};
use std::convert::TryFrom;
let panic_empty_range = || {
panic!(

27
third_party/rust/fastrand/tests/smoke.rs поставляемый
Просмотреть файл

@ -1,11 +1,10 @@
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::*;
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test as test;
#[cfg(target_arch = "wasm32")]
#[cfg(all(target_family = "wasm", not(target_os = "wasi")))]
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn bool() {
for x in &[false, true] {
while fastrand::bool() != *x {}
@ -13,7 +12,6 @@ fn bool() {
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn u8() {
for x in 0..10 {
while fastrand::u8(..10) != x {}
@ -25,7 +23,6 @@ fn u8() {
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn i8() {
for x in -128..-120 {
while fastrand::i8(..-120) != x {}
@ -37,7 +34,6 @@ fn i8() {
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn u32() {
for n in 1u32..10_000 {
let n = n.wrapping_mul(n);
@ -51,7 +47,6 @@ fn u32() {
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn u64() {
for n in 1u64..10_000 {
let n = n.wrapping_mul(n);
@ -66,7 +61,6 @@ fn u64() {
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn u128() {
for n in 1u128..10_000 {
let n = n.wrapping_mul(n);
@ -82,7 +76,18 @@ fn u128() {
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn fill() {
let r = fastrand::Rng::new();
let mut a = [0u8; 64];
let mut b = [0u8; 64];
r.fill(&mut a);
r.fill(&mut b);
assert_ne!(a, b);
}
#[test]
fn rng() {
let r = fastrand::Rng::new();
@ -96,7 +101,6 @@ fn rng() {
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn rng_init() {
let a = fastrand::Rng::new();
let b = fastrand::Rng::new();
@ -108,7 +112,6 @@ fn rng_init() {
}
#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn with_seed() {
let a = fastrand::Rng::with_seed(7);
let b = fastrand::Rng::new();