Refactor CompressionPiece constructor to accept string by reference and clean up unused comments
This commit is contained in:
@@ -178,9 +178,6 @@ void CompressionCommandAlternative(const uchar* rom_data,
|
|||||||
comp_accumulator = 0;
|
comp_accumulator = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================================================================
|
|
||||||
// Compression V2
|
|
||||||
|
|
||||||
void CheckByteRepeatV2(const uchar* data, uint& src_pos, const uint last_pos,
|
void CheckByteRepeatV2(const uchar* data, uint& src_pos, const uint last_pos,
|
||||||
CompressionCommand& cmd) {
|
CompressionCommand& cmd) {
|
||||||
uint i = 0;
|
uint i = 0;
|
||||||
@@ -379,15 +376,17 @@ absl::StatusOr<CompressionPiecePointer> SplitCompressionPiece(
|
|||||||
new_piece->argument[0] =
|
new_piece->argument[0] =
|
||||||
(char)(piece->argument[0] + kMaxLengthCompression);
|
(char)(piece->argument[0] + kMaxLengthCompression);
|
||||||
break;
|
break;
|
||||||
case kCommandDirectCopy:
|
case kCommandDirectCopy: {
|
||||||
|
std::string empty;
|
||||||
piece->argument_length = kMaxLengthCompression;
|
piece->argument_length = kMaxLengthCompression;
|
||||||
new_piece = std::make_shared<CompressionPiece>(
|
new_piece = std::make_shared<CompressionPiece>(
|
||||||
piece->command, length_left, nullptr, length_left);
|
piece->command, length_left, empty, length_left);
|
||||||
// MEMCPY
|
// MEMCPY
|
||||||
for (int i = 0; i < length_left; ++i) {
|
for (int i = 0; i < length_left; ++i) {
|
||||||
new_piece->argument[i] = piece->argument[i + kMaxLengthCompression];
|
new_piece->argument[i] = piece->argument[i + kMaxLengthCompression];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case kCommandRepeatingBytes: {
|
case kCommandRepeatingBytes: {
|
||||||
piece->argument_length = kMaxLengthCompression;
|
piece->argument_length = kMaxLengthCompression;
|
||||||
uint offset = piece->argument[0] + (piece->argument[1] << 8);
|
uint offset = piece->argument[0] + (piece->argument[1] << 8);
|
||||||
@@ -525,7 +524,9 @@ absl::StatusOr<std::vector<uint8_t>> CompressV2(const uchar* data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Worst case should be a copy of the string with extended header
|
// Worst case should be a copy of the string with extended header
|
||||||
auto compressed_chain = std::make_shared<CompressionPiece>(1, 1, "aaa", 2);
|
std::string worst_case = "aaa";
|
||||||
|
auto compressed_chain =
|
||||||
|
std::make_shared<CompressionPiece>(1, 1, worst_case, 2);
|
||||||
auto compressed_chain_start = compressed_chain;
|
auto compressed_chain_start = compressed_chain;
|
||||||
|
|
||||||
CompressionCommand current_cmd = {/*argument*/ {{}},
|
CompressionCommand current_cmd = {/*argument*/ {{}},
|
||||||
@@ -1208,15 +1209,17 @@ absl::StatusOr<CompressionPiece> SplitCompressionPieceV3(
|
|||||||
piece.argument_length);
|
piece.argument_length);
|
||||||
new_piece.argument[0] = (char)(piece.argument[0] + kMaxLengthCompression);
|
new_piece.argument[0] = (char)(piece.argument[0] + kMaxLengthCompression);
|
||||||
break;
|
break;
|
||||||
case kCommandDirectCopy:
|
case kCommandDirectCopy: {
|
||||||
piece.argument_length = kMaxLengthCompression;
|
piece.argument_length = kMaxLengthCompression;
|
||||||
new_piece =
|
std::string empty_string = "";
|
||||||
CompressionPiece(piece.command, length_left, nullptr, length_left);
|
new_piece = CompressionPiece(piece.command, length_left, empty_string,
|
||||||
|
length_left);
|
||||||
// MEMCPY
|
// MEMCPY
|
||||||
for (int i = 0; i < length_left; ++i) {
|
for (int i = 0; i < length_left; ++i) {
|
||||||
new_piece.argument[i] = piece.argument[i + kMaxLengthCompression];
|
new_piece.argument[i] = piece.argument[i + kMaxLengthCompression];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case kCommandRepeatingBytes: {
|
case kCommandRepeatingBytes: {
|
||||||
piece.argument_length = kMaxLengthCompression;
|
piece.argument_length = kMaxLengthCompression;
|
||||||
uint offset = piece.argument[0] + (piece.argument[1] << 8);
|
uint offset = piece.argument[0] + (piece.argument[1] << 8);
|
||||||
@@ -1339,8 +1342,6 @@ absl::StatusOr<std::vector<uint8_t>> CompressV3(
|
|||||||
context.compressed_data.end());
|
context.compressed_data.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decompression
|
|
||||||
|
|
||||||
std::string SetBuffer(const uchar* data, int src_pos, int comp_accumulator) {
|
std::string SetBuffer(const uchar* data, int src_pos, int comp_accumulator) {
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
for (int i = 0; i < comp_accumulator; ++i) {
|
for (int i = 0; i < comp_accumulator; ++i) {
|
||||||
@@ -1472,5 +1473,4 @@ absl::StatusOr<std::vector<uint8_t>> DecompressOverworld(
|
|||||||
|
|
||||||
} // namespace lc_lz2
|
} // namespace lc_lz2
|
||||||
} // namespace gfx
|
} // namespace gfx
|
||||||
|
} // namespace yaze
|
||||||
} // namespace yaze
|
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ struct CompressionPiece {
|
|||||||
std::string argument;
|
std::string argument;
|
||||||
std::shared_ptr<CompressionPiece> next = nullptr;
|
std::shared_ptr<CompressionPiece> next = nullptr;
|
||||||
CompressionPiece() = default;
|
CompressionPiece() = default;
|
||||||
CompressionPiece(int cmd, int len, std::string args, int arg_len)
|
CompressionPiece(int cmd, int len, std::string& args, int arg_len)
|
||||||
: command(cmd), length(len), argument_length(arg_len), argument(args) {}
|
: command(cmd), length(len), argument_length(arg_len), argument(args) {}
|
||||||
};
|
};
|
||||||
using CompressionPiece = struct CompressionPiece;
|
using CompressionPiece = struct CompressionPiece;
|
||||||
|
|||||||
Reference in New Issue
Block a user