OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // The main idea in Courgette is to do patching *under a tranformation*. The | 5 // The main idea in Courgette is to do patching *under a tranformation*. The |
6 // input is transformed into a new representation, patching occurs in the new | 6 // input is transformed into a new representation, patching occurs in the new |
7 // repesentation, and then the tranform is reversed to get the patched data. | 7 // repesentation, and then the tranform is reversed to get the patched data. |
8 // | 8 // |
9 // The idea is applied to pieces (or 'elements') of the whole (or 'ensemble'). | 9 // The idea is applied to pieces (or 'elements') of the whole (or 'ensemble'). |
10 // Each of the elements has to go through the same set of steps in lock-step. | 10 // Each of the elements has to go through the same set of steps in lock-step. |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 corrected_transformed_elements_source | 344 corrected_transformed_elements_source |
345 .Init(linearized_corrected_transformed_elements); | 345 .Init(linearized_corrected_transformed_elements); |
346 | 346 |
347 Status delta2_status = | 347 Status delta2_status = |
348 GenerateSimpleDelta(&predicted_transformed_elements_source, | 348 GenerateSimpleDelta(&predicted_transformed_elements_source, |
349 &corrected_transformed_elements_source, | 349 &corrected_transformed_elements_source, |
350 transformed_elements_correction); | 350 transformed_elements_correction); |
351 if (delta2_status != C_OK) | 351 if (delta2_status != C_OK) |
352 return delta2_status; | 352 return delta2_status; |
353 | 353 |
| 354 // Last use, free storage. |
| 355 linearized_predicted_transformed_elements.Retire(); |
| 356 |
354 // | 357 // |
355 // Generate sub-patch for whole enchilada. | 358 // Generate sub-patch for whole enchilada. |
356 // | 359 // |
357 SinkStream predicted_ensemble; | 360 SinkStream predicted_ensemble; |
358 | 361 |
359 predicted_ensemble.Write(base->Buffer(), base->Remaining()); | 362 predicted_ensemble.Write(base->Buffer(), base->Remaining()); |
360 | 363 |
361 SourceStreamSet corrected_transformed_elements_source_set; | 364 SourceStreamSet corrected_transformed_elements_source_set; |
362 corrected_transformed_elements_source | 365 corrected_transformed_elements_source |
363 .Init(linearized_corrected_transformed_elements); | 366 .Init(linearized_corrected_transformed_elements); |
(...skipping 10 matching lines...) Expand all Loading... |
374 &predicted_ensemble); | 377 &predicted_ensemble); |
375 if (status != C_OK) | 378 if (status != C_OK) |
376 return status; | 379 return status; |
377 if (!single_corrected_transformed_element.Empty()) | 380 if (!single_corrected_transformed_element.Empty()) |
378 return C_STREAM_NOT_CONSUMED; | 381 return C_STREAM_NOT_CONSUMED; |
379 } | 382 } |
380 | 383 |
381 if (!corrected_transformed_elements_source_set.Empty()) | 384 if (!corrected_transformed_elements_source_set.Empty()) |
382 return C_STREAM_NOT_CONSUMED; | 385 return C_STREAM_NOT_CONSUMED; |
383 | 386 |
| 387 // No more references to this stream's buffer. |
| 388 linearized_corrected_transformed_elements.Retire(); |
| 389 |
384 FreeGenerators(&generators); | 390 FreeGenerators(&generators); |
385 | 391 |
| 392 size_t final_patch_input_size = predicted_ensemble.Length(); |
386 SourceStream predicted_ensemble_source; | 393 SourceStream predicted_ensemble_source; |
387 predicted_ensemble_source.Init(predicted_ensemble); | 394 predicted_ensemble_source.Init(predicted_ensemble); |
388 Status delta3_status = GenerateSimpleDelta(&predicted_ensemble_source, | 395 Status delta3_status = GenerateSimpleDelta(&predicted_ensemble_source, |
389 update, | 396 update, |
390 ensemble_correction); | 397 ensemble_correction); |
391 if (delta3_status != C_OK) | 398 if (delta3_status != C_OK) |
392 return delta3_status; | 399 return delta3_status; |
393 | 400 |
394 // | 401 // |
395 // Final output stream has a header followed by a StreamSet. | 402 // Final output stream has a header followed by a StreamSet. |
396 // | 403 // |
397 final_patch->WriteVarint32(CourgettePatchFile::kMagic); | 404 final_patch->WriteVarint32(CourgettePatchFile::kMagic); |
398 final_patch->WriteVarint32(CourgettePatchFile::kVersion); | 405 final_patch->WriteVarint32(CourgettePatchFile::kVersion); |
399 | 406 |
400 final_patch->WriteVarint32( | 407 final_patch->WriteVarint32( |
401 CalculateCrc(old_region.start(), old_region.length())); | 408 CalculateCrc(old_region.start(), old_region.length())); |
402 final_patch->WriteVarint32( | 409 final_patch->WriteVarint32( |
403 CalculateCrc(new_region.start(), new_region.length())); | 410 CalculateCrc(new_region.start(), new_region.length())); |
| 411 final_patch->WriteSizeVarint32(final_patch_input_size); |
404 | 412 |
405 if (!patch_streams.CopyTo(final_patch)) | 413 if (!patch_streams.CopyTo(final_patch)) |
406 return C_STREAM_ERROR; | 414 return C_STREAM_ERROR; |
407 | 415 |
408 VLOG(1) << "done GenerateEnsemblePatch " | 416 VLOG(1) << "done GenerateEnsemblePatch " |
409 << (base::Time::Now() - start_time).InSecondsF() << "s"; | 417 << (base::Time::Now() - start_time).InSecondsF() << "s"; |
410 | 418 |
411 return C_OK; | 419 return C_OK; |
412 } | 420 } |
413 | 421 |
414 } // namespace | 422 } // namespace |
OLD | NEW |