| 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 #include "courgette/encoded_program.h" | 5 #include "courgette/encoded_program.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 188 |
| 189 void EncodedProgram::AddCopy(uint32 count, const void* bytes) { | 189 void EncodedProgram::AddCopy(uint32 count, const void* bytes) { |
| 190 const uint8* source = static_cast<const uint8*>(bytes); | 190 const uint8* source = static_cast<const uint8*>(bytes); |
| 191 | 191 |
| 192 // Fold adjacent COPY instructions into one. This nearly halves the size of | 192 // Fold adjacent COPY instructions into one. This nearly halves the size of |
| 193 // an EncodedProgram with only COPY1 instructions since there are approx plain | 193 // an EncodedProgram with only COPY1 instructions since there are approx plain |
| 194 // 16 bytes per reloc. This has a working-set benefit during decompression. | 194 // 16 bytes per reloc. This has a working-set benefit during decompression. |
| 195 // For compression of files with large differences this makes a small (4%) | 195 // For compression of files with large differences this makes a small (4%) |
| 196 // improvement in size. For files with small differences this degrades the | 196 // improvement in size. For files with small differences this degrades the |
| 197 // compressed size by 1.3% | 197 // compressed size by 1.3% |
| 198 if (ops_.size() > 0) { | 198 if (!ops_.empty()) { |
| 199 if (ops_.back() == COPY1) { | 199 if (ops_.back() == COPY1) { |
| 200 ops_.back() = COPY; | 200 ops_.back() = COPY; |
| 201 copy_counts_.push_back(1); | 201 copy_counts_.push_back(1); |
| 202 } | 202 } |
| 203 if (ops_.back() == COPY) { | 203 if (ops_.back() == COPY) { |
| 204 copy_counts_.back() += count; | 204 copy_counts_.back() += count; |
| 205 for (uint32 i = 0; i < count; ++i) { | 205 for (uint32 i = 0; i < count; ++i) { |
| 206 copy_bytes_.push_back(source[i]); | 206 copy_bytes_.push_back(source[i]); |
| 207 } | 207 } |
| 208 return; | 208 return; |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 if (assembled) | 563 if (assembled) |
| 564 return C_OK; | 564 return C_OK; |
| 565 return C_ASSEMBLY_FAILED; | 565 return C_ASSEMBLY_FAILED; |
| 566 } | 566 } |
| 567 | 567 |
| 568 void DeleteEncodedProgram(EncodedProgram* encoded) { | 568 void DeleteEncodedProgram(EncodedProgram* encoded) { |
| 569 delete encoded; | 569 delete encoded; |
| 570 } | 570 } |
| 571 | 571 |
| 572 } // end namespace | 572 } // end namespace |
| OLD | NEW |