File tree Expand file tree Collapse file tree 14 files changed +50
-86
lines changed Expand file tree Collapse file tree 14 files changed +50
-86
lines changed Original file line number Diff line number Diff line change @@ -36,15 +36,13 @@ impl BrotliDecoder {
3636 input : & mut PartialBuffer < & [ u8 ] > ,
3737 output : & mut WriteBuffer < ' _ > ,
3838 ) -> io:: Result < BrotliResult > {
39- output. initialize_unwritten ( ) ;
40-
4139 let in_buf = input. unwritten ( ) ;
42- let out_buf = output. unwritten_initialized_mut ( ) ;
40+ let out_buf = output. initialize_unwritten ( ) ;
4341
4442 let mut input_len = 0 ;
4543 let mut output_len = 0 ;
4644
47- let status = match BrotliDecompressStream (
45+ let result = match BrotliDecompressStream (
4846 & mut in_buf. len ( ) ,
4947 & mut input_len,
5048 in_buf,
@@ -54,14 +52,14 @@ impl BrotliDecoder {
5452 & mut 0 ,
5553 & mut self . state ,
5654 ) {
57- BrotliResult :: ResultFailure => return Err ( io:: Error :: other ( "brotli error" ) ) ,
58- status => status,
55+ BrotliResult :: ResultFailure => Err ( io:: Error :: other ( "brotli error" ) ) ,
56+ status => Ok ( status) ,
5957 } ;
6058
6159 input. advance ( input_len) ;
6260 output. advance ( output_len) ;
6361
64- Ok ( status )
62+ result
6563 }
6664}
6765
Original file line number Diff line number Diff line change @@ -25,15 +25,13 @@ impl BrotliEncoder {
2525 output : & mut WriteBuffer < ' _ > ,
2626 op : BrotliEncoderOperation ,
2727 ) -> io:: Result < ( ) > {
28- output. initialize_unwritten ( ) ;
29-
3028 let in_buf = input. unwritten ( ) ;
31- let out_buf = output. unwritten_initialized_mut ( ) ;
29+ let out_buf = output. initialize_unwritten ( ) ;
3230
3331 let mut input_len = 0 ;
3432 let mut output_len = 0 ;
3533
36- if !self . state . compress_stream (
34+ let result = if !self . state . compress_stream (
3735 op,
3836 & mut in_buf. len ( ) ,
3937 in_buf,
@@ -44,13 +42,15 @@ impl BrotliEncoder {
4442 & mut None ,
4543 & mut |_, _, _, _| ( ) ,
4644 ) {
47- return Err ( io:: Error :: other ( "brotli error" ) ) ;
48- }
45+ Err ( io:: Error :: other ( "brotli error" ) )
46+ } else {
47+ Ok ( ( ) )
48+ } ;
4949
5050 input. advance ( input_len) ;
5151 output. advance ( output_len) ;
5252
53- Ok ( ( ) )
53+ result
5454 }
5555}
5656
Original file line number Diff line number Diff line change @@ -38,25 +38,23 @@ impl BzDecoder {
3838 input : & mut PartialBuffer < & [ u8 ] > ,
3939 output : & mut WriteBuffer < ' _ > ,
4040 ) -> io:: Result < Status > {
41- output. initialize_unwritten ( ) ;
42-
4341 let prior_in = self . decompress . total_in ( ) ;
4442 let prior_out = self . decompress . total_out ( ) ;
4543
46- let status = self
44+ let result = self
4745 . decompress
48- . decompress ( input. unwritten ( ) , output. unwritten_initialized_mut ( ) )
49- . map_err ( io:: Error :: other) ? ;
46+ . decompress ( input. unwritten ( ) , output. initialize_unwritten ( ) )
47+ . map_err ( io:: Error :: other) ;
5048
5149 input. advance ( ( self . decompress . total_in ( ) - prior_in) as usize ) ;
5250 output. advance ( ( self . decompress . total_out ( ) - prior_out) as usize ) ;
5351
5452 // Track when stream has properly ended
55- if status == Status :: StreamEnd {
53+ if matches ! ( result , Ok ( Status :: StreamEnd ) ) {
5654 self . stream_ended = true ;
5755 }
5856
59- Ok ( status )
57+ result
6058 }
6159}
6260
Original file line number Diff line number Diff line change @@ -52,24 +52,18 @@ impl BzEncoder {
5252 output : & mut WriteBuffer < ' _ > ,
5353 action : Action ,
5454 ) -> io:: Result < Status > {
55- output. initialize_unwritten ( ) ;
56-
5755 let prior_in = self . compress . total_in ( ) ;
5856 let prior_out = self . compress . total_out ( ) ;
5957
60- let status = self
58+ let result = self
6159 . compress
62- . compress (
63- input. unwritten ( ) ,
64- output. unwritten_initialized_mut ( ) ,
65- action,
66- )
67- . map_err ( io:: Error :: other) ?;
60+ . compress ( input. unwritten ( ) , output. initialize_unwritten ( ) , action)
61+ . map_err ( io:: Error :: other) ;
6862
6963 input. advance ( ( self . compress . total_in ( ) - prior_in) as usize ) ;
7064 output. advance ( ( self . compress . total_out ( ) - prior_out) as usize ) ;
7165
72- Ok ( status )
66+ result
7367 }
7468}
7569
Original file line number Diff line number Diff line change @@ -26,11 +26,9 @@ impl Deflate64Decoder {
2626 input : & mut PartialBuffer < & [ u8 ] > ,
2727 output : & mut WriteBuffer < ' _ > ,
2828 ) -> Result < bool > {
29- output. initialize_unwritten ( ) ;
30-
3129 let result = self
3230 . inflater
33- . inflate ( input. unwritten ( ) , output. unwritten_initialized_mut ( ) ) ;
31+ . inflate ( input. unwritten ( ) , output. initialize_unwritten ( ) ) ;
3432
3533 input. advance ( result. bytes_consumed ) ;
3634 output. advance ( result. bytes_written ) ;
Original file line number Diff line number Diff line change @@ -23,21 +23,17 @@ impl FlateDecoder {
2323 output : & mut WriteBuffer < ' _ > ,
2424 flush : FlushDecompress ,
2525 ) -> io:: Result < Status > {
26- output. initialize_unwritten ( ) ;
27-
2826 let prior_in = self . decompress . total_in ( ) ;
2927 let prior_out = self . decompress . total_out ( ) ;
3028
31- let status = self . decompress . decompress (
32- input. unwritten ( ) ,
33- output. unwritten_initialized_mut ( ) ,
34- flush,
35- ) ?;
29+ let result =
30+ self . decompress
31+ . decompress ( input. unwritten ( ) , output. initialize_unwritten ( ) , flush) ;
3632
3733 input. advance ( ( self . decompress . total_in ( ) - prior_in) as usize ) ;
3834 output. advance ( ( self . decompress . total_out ( ) - prior_out) as usize ) ;
3935
40- Ok ( status )
36+ Ok ( result? )
4137 }
4238}
4339
Original file line number Diff line number Diff line change @@ -28,19 +28,17 @@ impl FlateEncoder {
2828 output : & mut WriteBuffer < ' _ > ,
2929 flush : FlushCompress ,
3030 ) -> io:: Result < Status > {
31- output. initialize_unwritten ( ) ;
32-
3331 let prior_in = self . compress . total_in ( ) ;
3432 let prior_out = self . compress . total_out ( ) ;
3533
36- let status =
34+ let result =
3735 self . compress
38- . compress ( input. unwritten ( ) , output. unwritten_initialized_mut ( ) , flush) ? ;
36+ . compress ( input. unwritten ( ) , output. initialize_unwritten ( ) , flush) ;
3937
4038 input. advance ( ( self . compress . total_in ( ) - prior_in) as usize ) ;
4139 output. advance ( ( self . compress . total_out ( ) - prior_out) as usize ) ;
4240
43- Ok ( status )
41+ Ok ( result? )
4442 }
4543}
4644
Original file line number Diff line number Diff line change @@ -61,24 +61,24 @@ impl DecodeV2 for Lz4Decoder {
6161 input : & mut PartialBuffer < & [ u8 ] > ,
6262 output : & mut WriteBuffer < ' _ > ,
6363 ) -> Result < bool > {
64- output. initialize_unwritten ( ) ;
64+ let out_buf = output. initialize_unwritten ( ) ;
6565
66- let mut output_size = output . unwritten_initialized_mut ( ) . len ( ) ;
66+ let mut output_size = out_buf . len ( ) ;
6767 let mut input_size = input. unwritten ( ) . len ( ) ;
68- let remaining = unsafe {
68+ let result = unsafe {
6969 check_error ( LZ4F_decompress (
7070 self . ctx . get_mut ( ) . ctx ,
71- output . unwritten_initialized_mut ( ) . as_mut_ptr ( ) ,
71+ out_buf . as_mut_ptr ( ) ,
7272 & mut output_size,
7373 input. unwritten ( ) . as_ptr ( ) ,
7474 & mut input_size,
7575 core:: ptr:: null ( ) ,
76- ) ) ?
76+ ) )
7777 } ;
7878 input. advance ( input_size) ;
7979 output. advance ( output_size) ;
8080
81- let finished = remaining == 0 ;
81+ let finished = result? == 0 ;
8282 if finished {
8383 self . stream_ended = true ;
8484 }
Original file line number Diff line number Diff line change @@ -117,8 +117,8 @@ impl Lz4Encoder {
117117 Lz4Fn :: Flush | Lz4Fn :: End => self . flush_buffer_size ,
118118 } ;
119119
120- output. initialize_unwritten ( ) ;
121- let output_len = output . unwritten_initialized_mut ( ) . len ( ) ;
120+ let out_buf = output. initialize_unwritten ( ) ;
121+ let output_len = out_buf . len ( ) ;
122122
123123 let ( dst_buffer, dst_size, maybe_internal_buffer) = if min_dst_size > output_len {
124124 let buffer_size = self . block_buffer_size ;
@@ -132,11 +132,7 @@ impl Lz4Encoder {
132132 Some ( buffer) ,
133133 )
134134 } else {
135- (
136- output. unwritten_initialized_mut ( ) . as_mut_ptr ( ) ,
137- output_len,
138- None ,
139- )
135+ ( out_buf. as_mut_ptr ( ) , output_len, None )
140136 } ;
141137
142138 let len = match lz4_fn {
Original file line number Diff line number Diff line change @@ -62,10 +62,9 @@ impl Xz2Decoder {
6262 ) -> io:: Result < bool > {
6363 let previous_out = self . stream . total_out ( ) as usize ;
6464
65- output. initialize_unwritten ( ) ;
6665 let status = self
6766 . stream
68- . process ( input, output. unwritten_initialized_mut ( ) , action) ?;
67+ . process ( input, output. initialize_unwritten ( ) , action) ?;
6968
7069 output. advance ( self . stream . total_out ( ) as usize - previous_out) ;
7170
You can’t perform that action at this time.
0 commit comments