@@ -150,14 +150,14 @@ impl<const N: usize, G: Generator<Output = [u32; N]>> BlockRng<G> {
150150 /// This will force a new set of results to be generated on next use.
151151 #[ inline]
152152 pub fn reset ( & mut self ) {
153- self . index = self . results . len ( ) ;
153+ self . index = N ;
154154 }
155155
156156 /// Generate a new set of results immediately, setting the index to the
157157 /// given value.
158158 #[ inline]
159159 pub fn generate_and_set ( & mut self , index : usize ) {
160- assert ! ( index < self . results . len ( ) ) ;
160+ assert ! ( index < N ) ;
161161 self . core . generate ( & mut self . results ) ;
162162 self . index = index;
163163 }
@@ -166,7 +166,7 @@ impl<const N: usize, G: Generator<Output = [u32; N]>> BlockRng<G> {
166166impl < const N : usize , G : Generator < Output = [ u32 ; N ] > > RngCore for BlockRng < G > {
167167 #[ inline]
168168 fn next_u32 ( & mut self ) -> u32 {
169- if self . index >= self . results . len ( ) {
169+ if self . index >= N {
170170 self . generate_and_set ( 0 ) ;
171171 }
172172
@@ -182,18 +182,16 @@ impl<const N: usize, G: Generator<Output = [u32; N]>> RngCore for BlockRng<G> {
182182 ( u64:: from ( data[ 1 ] ) << 32 ) | u64:: from ( data[ 0 ] )
183183 } ;
184184
185- let len = self . results . len ( ) ;
186-
187185 let index = self . index ;
188- if index < len - 1 {
186+ if index < N - 1 {
189187 self . index += 2 ;
190188 // Read an u64 from the current index
191189 read_u64 ( & self . results , index)
192- } else if index >= len {
190+ } else if index >= N {
193191 self . generate_and_set ( 2 ) ;
194192 read_u64 ( & self . results , 0 )
195193 } else {
196- let x = u64:: from ( self . results [ len - 1 ] ) ;
194+ let x = u64:: from ( self . results [ N - 1 ] ) ;
197195 self . generate_and_set ( 1 ) ;
198196 let y = u64:: from ( self . results [ 0 ] ) ;
199197 ( y << 32 ) | x
@@ -204,7 +202,7 @@ impl<const N: usize, G: Generator<Output = [u32; N]>> RngCore for BlockRng<G> {
204202 fn fill_bytes ( & mut self , dest : & mut [ u8 ] ) {
205203 let mut read_len = 0 ;
206204 while read_len < dest. len ( ) {
207- if self . index >= self . results . len ( ) {
205+ if self . index >= N {
208206 self . generate_and_set ( 0 ) ;
209207 }
210208 let ( consumed_u32, filled_u8) =
@@ -287,12 +285,11 @@ impl<const N: usize, G: Generator<Output = [u64; N]>> BlockRng64<G> {
287285 /// `Generator`. Results will be generated on first use.
288286 #[ inline]
289287 pub fn new ( core : G ) -> BlockRng64 < G > {
290- let results_empty = [ 0 ; N ] ;
291288 BlockRng64 {
292289 core,
293- index : results_empty . len ( ) ,
290+ index : N ,
294291 half_used : false ,
295- results : results_empty ,
292+ results : [ 0 ; N ] ,
296293 }
297294 }
298295
@@ -310,15 +307,15 @@ impl<const N: usize, G: Generator<Output = [u64; N]>> BlockRng64<G> {
310307 /// This will force a new set of results to be generated on next use.
311308 #[ inline]
312309 pub fn reset ( & mut self ) {
313- self . index = self . results . len ( ) ;
310+ self . index = N ;
314311 self . half_used = false ;
315312 }
316313
317314 /// Generate a new set of results immediately, setting the index to the
318315 /// given value.
319316 #[ inline]
320317 pub fn generate_and_set ( & mut self , index : usize ) {
321- assert ! ( index < self . results . len ( ) ) ;
318+ assert ! ( index < N ) ;
322319 self . core . generate ( & mut self . results ) ;
323320 self . index = index;
324321 self . half_used = false ;
@@ -329,7 +326,7 @@ impl<const N: usize, G: Generator<Output = [u64; N]>> RngCore for BlockRng64<G>
329326 #[ inline]
330327 fn next_u32 ( & mut self ) -> u32 {
331328 let mut index = self . index - self . half_used as usize ;
332- if index >= self . results . len ( ) {
329+ if index >= N {
333330 self . core . generate ( & mut self . results ) ;
334331 self . index = 0 ;
335332 index = 0 ;
@@ -347,7 +344,7 @@ impl<const N: usize, G: Generator<Output = [u64; N]>> RngCore for BlockRng64<G>
347344
348345 #[ inline]
349346 fn next_u64 ( & mut self ) -> u64 {
350- if self . index >= self . results . len ( ) {
347+ if self . index >= N {
351348 self . core . generate ( & mut self . results ) ;
352349 self . index = 0 ;
353350 }
@@ -363,7 +360,7 @@ impl<const N: usize, G: Generator<Output = [u64; N]>> RngCore for BlockRng64<G>
363360 let mut read_len = 0 ;
364361 self . half_used = false ;
365362 while read_len < dest. len ( ) {
366- if self . index >= self . results . len ( ) {
363+ if self . index >= N {
367364 self . core . generate ( & mut self . results ) ;
368365 self . index = 0 ;
369366 }
@@ -520,7 +517,7 @@ mod test {
520517 }
521518
522519 #[ test]
523- #[ should_panic( expected = "index < self.results.len() " ) ]
520+ #[ should_panic( expected = "index < N " ) ]
524521 fn blockrng64_generate_and_set_panic ( ) {
525522 let mut rng = BlockRng64 :: < DummyRng64 > :: from_seed ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] ) ;
526523 rng. generate_and_set ( rng. results . len ( ) ) ;
0 commit comments