@@ -131,6 +131,7 @@ impl<R: BlockRngCore + fmt::Debug> fmt::Debug for BlockRng<R> {
131
131
impl < R : BlockRngCore > BlockRng < R > {
132
132
/// Create a new `BlockRng` from an existing RNG implementing
133
133
/// `BlockRngCore`. Results will be generated on first use.
134
+ #[ inline]
134
135
pub fn new ( core : R ) -> BlockRng < R > {
135
136
let results_empty = R :: Results :: default ( ) ;
136
137
BlockRng {
@@ -145,18 +146,21 @@ impl<R: BlockRngCore> BlockRng<R> {
145
146
/// If this is equal to or larger than the size of the result buffer then
146
147
/// the buffer is "empty" and `generate()` must be called to produce new
147
148
/// results.
149
+ #[ inline( always) ]
148
150
pub fn index ( & self ) -> usize {
149
151
self . index
150
152
}
151
153
152
154
/// Reset the number of available results.
153
155
/// This will force a new set of results to be generated on next use.
156
+ #[ inline]
154
157
pub fn reset ( & mut self ) {
155
158
self . index = self . results . as_ref ( ) . len ( ) ;
156
159
}
157
160
158
161
/// Generate a new set of results immediately, setting the index to the
159
162
/// given value.
163
+ #[ inline]
160
164
pub fn generate_and_set ( & mut self , index : usize ) {
161
165
assert ! ( index < self . results. as_ref( ) . len( ) ) ;
162
166
self . core . generate ( & mut self . results ) ;
@@ -167,7 +171,7 @@ impl<R: BlockRngCore> BlockRng<R> {
167
171
impl < R : BlockRngCore < Item =u32 > > RngCore for BlockRng < R >
168
172
where <R as BlockRngCore >:: Results : AsRef < [ u32 ] > + AsMut < [ u32 ] >
169
173
{
170
- #[ inline( always ) ]
174
+ #[ inline]
171
175
fn next_u32 ( & mut self ) -> u32 {
172
176
if self . index >= self . results . as_ref ( ) . len ( ) {
173
177
self . generate_and_set ( 0 ) ;
@@ -178,7 +182,7 @@ where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
178
182
value
179
183
}
180
184
181
- #[ inline( always ) ]
185
+ #[ inline]
182
186
fn next_u64 ( & mut self ) -> u64 {
183
187
let read_u64 = |results : & [ u32 ] , index| {
184
188
if cfg ! ( any( target_endian = "little" ) ) {
@@ -210,6 +214,7 @@ where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
210
214
}
211
215
}
212
216
217
+ #[ inline]
213
218
fn fill_bytes ( & mut self , dest : & mut [ u8 ] ) {
214
219
let mut read_len = 0 ;
215
220
while read_len < dest. len ( ) {
@@ -225,23 +230,26 @@ where <R as BlockRngCore>::Results: AsRef<[u32]> + AsMut<[u32]>
225
230
}
226
231
}
227
232
233
+ #[ inline( always) ]
228
234
fn try_fill_bytes ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
229
- self . fill_bytes ( dest) ;
230
- Ok ( ( ) )
235
+ Ok ( self . fill_bytes ( dest) )
231
236
}
232
237
}
233
238
234
239
impl < R : BlockRngCore + SeedableRng > SeedableRng for BlockRng < R > {
235
240
type Seed = R :: Seed ;
236
241
242
+ #[ inline( always) ]
237
243
fn from_seed ( seed : Self :: Seed ) -> Self {
238
244
Self :: new ( R :: from_seed ( seed) )
239
245
}
240
246
247
+ #[ inline( always) ]
241
248
fn seed_from_u64 ( seed : u64 ) -> Self {
242
249
Self :: new ( R :: seed_from_u64 ( seed) )
243
250
}
244
251
252
+ #[ inline( always) ]
245
253
fn from_rng < S : RngCore > ( rng : S ) -> Result < Self , Error > {
246
254
Ok ( Self :: new ( R :: from_rng ( rng) ?) )
247
255
}
@@ -296,6 +304,7 @@ impl<R: BlockRngCore + fmt::Debug> fmt::Debug for BlockRng64<R> {
296
304
impl < R : BlockRngCore > BlockRng64 < R > {
297
305
/// Create a new `BlockRng` from an existing RNG implementing
298
306
/// `BlockRngCore`. Results will be generated on first use.
307
+ #[ inline]
299
308
pub fn new ( core : R ) -> BlockRng64 < R > {
300
309
let results_empty = R :: Results :: default ( ) ;
301
310
BlockRng64 {
@@ -311,19 +320,22 @@ impl<R: BlockRngCore> BlockRng64<R> {
311
320
/// If this is equal to or larger than the size of the result buffer then
312
321
/// the buffer is "empty" and `generate()` must be called to produce new
313
322
/// results.
323
+ #[ inline( always) ]
314
324
pub fn index ( & self ) -> usize {
315
325
self . index
316
326
}
317
327
318
328
/// Reset the number of available results.
319
329
/// This will force a new set of results to be generated on next use.
330
+ #[ inline]
320
331
pub fn reset ( & mut self ) {
321
332
self . index = self . results . as_ref ( ) . len ( ) ;
322
333
self . half_used = false ;
323
334
}
324
335
325
336
/// Generate a new set of results immediately, setting the index to the
326
337
/// given value.
338
+ #[ inline]
327
339
pub fn generate_and_set ( & mut self , index : usize ) {
328
340
assert ! ( index < self . results. as_ref( ) . len( ) ) ;
329
341
self . core . generate ( & mut self . results ) ;
@@ -335,7 +347,7 @@ impl<R: BlockRngCore> BlockRng64<R> {
335
347
impl < R : BlockRngCore < Item =u64 > > RngCore for BlockRng64 < R >
336
348
where <R as BlockRngCore >:: Results : AsRef < [ u64 ] > + AsMut < [ u64 ] >
337
349
{
338
- #[ inline( always ) ]
350
+ #[ inline]
339
351
fn next_u32 ( & mut self ) -> u32 {
340
352
let mut index = self . index * 2 - self . half_used as usize ;
341
353
if index >= self . results . as_ref ( ) . len ( ) * 2 {
@@ -361,7 +373,7 @@ where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]>
361
373
}
362
374
}
363
375
364
- #[ inline( always ) ]
376
+ #[ inline]
365
377
fn next_u64 ( & mut self ) -> u64 {
366
378
if self . index >= self . results . as_ref ( ) . len ( ) {
367
379
self . core . generate ( & mut self . results ) ;
@@ -374,6 +386,7 @@ where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]>
374
386
value
375
387
}
376
388
389
+ #[ inline]
377
390
fn fill_bytes ( & mut self , dest : & mut [ u8 ] ) {
378
391
let mut read_len = 0 ;
379
392
self . half_used = false ;
@@ -392,6 +405,7 @@ where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]>
392
405
}
393
406
}
394
407
408
+ #[ inline( always) ]
395
409
fn try_fill_bytes ( & mut self , dest : & mut [ u8 ] ) -> Result < ( ) , Error > {
396
410
Ok ( self . fill_bytes ( dest) )
397
411
}
@@ -400,14 +414,17 @@ where <R as BlockRngCore>::Results: AsRef<[u64]> + AsMut<[u64]>
400
414
impl < R : BlockRngCore + SeedableRng > SeedableRng for BlockRng64 < R > {
401
415
type Seed = R :: Seed ;
402
416
417
+ #[ inline( always) ]
403
418
fn from_seed ( seed : Self :: Seed ) -> Self {
404
419
Self :: new ( R :: from_seed ( seed) )
405
420
}
406
421
422
+ #[ inline( always) ]
407
423
fn seed_from_u64 ( seed : u64 ) -> Self {
408
424
Self :: new ( R :: seed_from_u64 ( seed) )
409
425
}
410
426
427
+ #[ inline( always) ]
411
428
fn from_rng < S : RngCore > ( rng : S ) -> Result < Self , Error > {
412
429
Ok ( Self :: new ( R :: from_rng ( rng) ?) )
413
430
}
0 commit comments