@@ -36,7 +36,7 @@ impl<T: Default> BitResult<T> {
3636}
3737
3838#[ cfg_attr( test, derive( Debug ) ) ]
39- pub ( crate ) struct BoolReader {
39+ pub ( crate ) struct ArithmeticDecoder {
4040 chunks : Box < [ [ u8 ; 4 ] ] > ,
4141 state : State ,
4242 final_bytes : [ u8 ; 3 ] ,
@@ -53,21 +53,21 @@ struct State {
5353}
5454
5555#[ cfg_attr( test, derive( Debug ) ) ]
56- struct FastReader < ' a > {
56+ struct FastDecoder < ' a > {
5757 chunks : & ' a [ [ u8 ; 4 ] ] ,
5858 uncommitted_state : State ,
5959 save_state : & ' a mut State ,
6060}
6161
62- impl BoolReader {
63- pub ( crate ) fn new ( ) -> BoolReader {
62+ impl ArithmeticDecoder {
63+ pub ( crate ) fn new ( ) -> ArithmeticDecoder {
6464 let state = State {
6565 chunk_index : 0 ,
6666 value : 0 ,
6767 range : 255 ,
6868 bit_count : -8 ,
6969 } ;
70- BoolReader {
70+ ArithmeticDecoder {
7171 chunks : Box :: new ( [ ] ) ,
7272 state,
7373 final_bytes : [ 0 ; 3 ] ,
@@ -117,7 +117,7 @@ impl BoolReader {
117117 /// discarded anyway.
118118 ///
119119 /// Each call to `start_accumulated_result` must be followed by a call to
120- /// `check` on the *same* `BoolReader `.
120+ /// `check` on the *same* `ArithmeticDecoder `.
121121 #[ inline( always) ]
122122 pub ( crate ) fn start_accumulated_result ( & mut self ) -> BitResultAccumulator {
123123 BitResultAccumulator
@@ -216,7 +216,7 @@ impl BoolReader {
216216 self . cold_read_with_tree ( tree, usize:: from ( first_node. index ) )
217217 }
218218
219- // As a similar (but different) speedup to BitResult, the FastReader reads
219+ // As a similar (but different) speedup to BitResult, the FastDecoder reads
220220 // bits under an assumption and validates it at the end.
221221 //
222222 // The idea here is that for normal-sized webp images, the vast majority
@@ -228,8 +228,8 @@ impl BoolReader {
228228 // work for those last few bytes -- in fact we even keep retrying the fast
229229 // method to save an if-statement --, but more than make up for that by
230230 // speeding up reading from the other thousands or millions of bytes.
231- fn fast ( & mut self ) -> FastReader < ' _ > {
232- FastReader {
231+ fn fast ( & mut self ) -> FastDecoder < ' _ > {
232+ FastDecoder {
233233 chunks : & self . chunks ,
234234 uncommitted_state : self . state ,
235235 save_state : & mut self . state ,
@@ -377,7 +377,7 @@ impl BoolReader {
377377 }
378378}
379379
380- impl FastReader < ' _ > {
380+ impl FastDecoder < ' _ > {
381381 fn commit_if_valid < T > ( self , value_if_not_past_eof : T ) -> Option < T > {
382382 // If `chunk_index > self.chunks.len()`, it means we used zeroes
383383 // instead of an actual chunk and `value_if_not_past_eof` is nonsense.
@@ -564,50 +564,50 @@ mod tests {
564564 use super :: * ;
565565
566566 #[ test]
567- fn test_bool_reader_hello_short ( ) {
568- let mut reader = BoolReader :: new ( ) ;
567+ fn test_arithmetic_decoder_hello_short ( ) {
568+ let mut decoder = ArithmeticDecoder :: new ( ) ;
569569 let data = b"hel" ;
570570 let size = data. len ( ) ;
571571 let mut buf = vec ! [ [ 0u8 ; 4 ] ; 1 ] ;
572572 buf. as_mut_slice ( ) . as_flattened_mut ( ) [ ..size] . copy_from_slice ( & data[ ..] ) ;
573- reader . init ( buf, size) . unwrap ( ) ;
574- let mut res = reader . start_accumulated_result ( ) ;
575- assert_eq ! ( false , reader . read_flag( ) . or_accumulate( & mut res) ) ;
576- assert_eq ! ( true , reader . read_bool( 10 ) . or_accumulate( & mut res) ) ;
577- assert_eq ! ( false , reader . read_bool( 250 ) . or_accumulate( & mut res) ) ;
578- assert_eq ! ( 1 , reader . read_literal( 1 ) . or_accumulate( & mut res) ) ;
579- assert_eq ! ( 5 , reader . read_literal( 3 ) . or_accumulate( & mut res) ) ;
580- assert_eq ! ( 64 , reader . read_literal( 8 ) . or_accumulate( & mut res) ) ;
581- assert_eq ! ( 185 , reader . read_literal( 8 ) . or_accumulate( & mut res) ) ;
582- reader . check ( res, ( ) ) . unwrap ( ) ;
573+ decoder . init ( buf, size) . unwrap ( ) ;
574+ let mut res = decoder . start_accumulated_result ( ) ;
575+ assert_eq ! ( false , decoder . read_flag( ) . or_accumulate( & mut res) ) ;
576+ assert_eq ! ( true , decoder . read_bool( 10 ) . or_accumulate( & mut res) ) ;
577+ assert_eq ! ( false , decoder . read_bool( 250 ) . or_accumulate( & mut res) ) ;
578+ assert_eq ! ( 1 , decoder . read_literal( 1 ) . or_accumulate( & mut res) ) ;
579+ assert_eq ! ( 5 , decoder . read_literal( 3 ) . or_accumulate( & mut res) ) ;
580+ assert_eq ! ( 64 , decoder . read_literal( 8 ) . or_accumulate( & mut res) ) ;
581+ assert_eq ! ( 185 , decoder . read_literal( 8 ) . or_accumulate( & mut res) ) ;
582+ decoder . check ( res, ( ) ) . unwrap ( ) ;
583583 }
584584
585585 #[ test]
586- fn test_bool_reader_hello_long ( ) {
587- let mut reader = BoolReader :: new ( ) ;
586+ fn test_arithmetic_decoder_hello_long ( ) {
587+ let mut decoder = ArithmeticDecoder :: new ( ) ;
588588 let data = b"hello world" ;
589589 let size = data. len ( ) ;
590590 let mut buf = vec ! [ [ 0u8 ; 4 ] ; ( size + 3 ) / 4 ] ;
591591 buf. as_mut_slice ( ) . as_flattened_mut ( ) [ ..size] . copy_from_slice ( & data[ ..] ) ;
592- reader . init ( buf, size) . unwrap ( ) ;
593- let mut res = reader . start_accumulated_result ( ) ;
594- assert_eq ! ( false , reader . read_flag( ) . or_accumulate( & mut res) ) ;
595- assert_eq ! ( true , reader . read_bool( 10 ) . or_accumulate( & mut res) ) ;
596- assert_eq ! ( false , reader . read_bool( 250 ) . or_accumulate( & mut res) ) ;
597- assert_eq ! ( 1 , reader . read_literal( 1 ) . or_accumulate( & mut res) ) ;
598- assert_eq ! ( 5 , reader . read_literal( 3 ) . or_accumulate( & mut res) ) ;
599- assert_eq ! ( 64 , reader . read_literal( 8 ) . or_accumulate( & mut res) ) ;
600- assert_eq ! ( 185 , reader . read_literal( 8 ) . or_accumulate( & mut res) ) ;
601- assert_eq ! ( 31 , reader . read_literal( 8 ) . or_accumulate( & mut res) ) ;
602- reader . check ( res, ( ) ) . unwrap ( ) ;
592+ decoder . init ( buf, size) . unwrap ( ) ;
593+ let mut res = decoder . start_accumulated_result ( ) ;
594+ assert_eq ! ( false , decoder . read_flag( ) . or_accumulate( & mut res) ) ;
595+ assert_eq ! ( true , decoder . read_bool( 10 ) . or_accumulate( & mut res) ) ;
596+ assert_eq ! ( false , decoder . read_bool( 250 ) . or_accumulate( & mut res) ) ;
597+ assert_eq ! ( 1 , decoder . read_literal( 1 ) . or_accumulate( & mut res) ) ;
598+ assert_eq ! ( 5 , decoder . read_literal( 3 ) . or_accumulate( & mut res) ) ;
599+ assert_eq ! ( 64 , decoder . read_literal( 8 ) . or_accumulate( & mut res) ) ;
600+ assert_eq ! ( 185 , decoder . read_literal( 8 ) . or_accumulate( & mut res) ) ;
601+ assert_eq ! ( 31 , decoder . read_literal( 8 ) . or_accumulate( & mut res) ) ;
602+ decoder . check ( res, ( ) ) . unwrap ( ) ;
603603 }
604604
605605 #[ test]
606- fn test_bool_reader_uninit ( ) {
607- let mut reader = BoolReader :: new ( ) ;
608- let mut res = reader . start_accumulated_result ( ) ;
609- let _ = reader . read_flag ( ) . or_accumulate ( & mut res) ;
610- let result = reader . check ( res, ( ) ) ;
606+ fn test_arithmetic_decoder_uninit ( ) {
607+ let mut decoder = ArithmeticDecoder :: new ( ) ;
608+ let mut res = decoder . start_accumulated_result ( ) ;
609+ let _ = decoder . read_flag ( ) . or_accumulate ( & mut res) ;
610+ let result = decoder . check ( res, ( ) ) ;
611611 assert ! ( result. is_err( ) ) ;
612612 }
613613}
0 commit comments