@@ -128,12 +128,6 @@ static uint64_t bps_decode(struct bps_data *bps)
128128 return data ;
129129}
130130
131- static void bps_write (struct bps_data * bps , uint8_t data )
132- {
133- bps -> target_data [bps -> output_offset ++ ] = data ;
134- bps -> target_checksum = ~(encoding_crc32 (~bps -> target_checksum , & data , 1 ));
135- }
136-
137131static enum patch_error bps_apply_patch (
138132 const uint8_t * modify_data , uint64_t modify_length ,
139133 const uint8_t * source_data , uint64_t source_length ,
@@ -208,12 +202,20 @@ static enum patch_error bps_apply_patch(
208202 {
209203 case SOURCE_READ :
210204 while (length -- )
211- bps_write (& bps , bps .source_data [bps .output_offset ]);
205+ {
206+ uint8_t data = bps .source_data [bps .output_offset ];
207+ bps .target_data [bps .output_offset ++ ] = data ;
208+ bps .target_checksum = ~(encoding_crc32 (~bps .target_checksum , & data , 1 ));
209+ }
212210 break ;
213211
214212 case TARGET_READ :
215213 while (length -- )
216- bps_write (& bps , bps_read (& bps ));
214+ {
215+ uint8_t data = bps_read (& bps );
216+ bps .target_data [bps .output_offset ++ ] = data ;
217+ bps .target_checksum = ~(encoding_crc32 (~bps .target_checksum , & data , 1 ));
218+ }
217219 break ;
218220
219221 case SOURCE_COPY :
@@ -231,13 +233,21 @@ static enum patch_error bps_apply_patch(
231233 {
232234 bps .source_offset += offset ;
233235 while (length -- )
234- bps_write (& bps , bps .source_data [bps .source_offset ++ ]);
236+ {
237+ uint8_t data = bps .source_data [bps .source_offset ++ ];
238+ bps .target_data [bps .output_offset ++ ] = data ;
239+ bps .target_checksum = ~(encoding_crc32 (~bps .target_checksum , & data , 1 ));
240+ }
235241 }
236242 else
237243 {
238244 bps .target_offset += offset ;
239245 while (length -- )
240- bps_write (& bps , bps .target_data [bps .target_offset ++ ]);
246+ {
247+ uint8_t data = bps .target_data [bps .target_offset ++ ];
248+ bps .target_data [bps .output_offset ++ ] = data ;
249+ bps .target_checksum = ~(encoding_crc32 (~bps .target_checksum , & data , 1 ));
250+ }
241251 break ;
242252 }
243253 break ;
0 commit comments