summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/CompressedBlob.cpp
diff options
context:
space:
mode:
authorUnknown W. Brackets <checkins@unknownbrackets.org>2014-11-27 08:57:49 -0800
committerUnknown W. Brackets <checkins@unknownbrackets.org>2014-11-27 08:58:09 -0800
commitf54bf815208e61977392753b984e20abb8086c5f (patch)
treee547070a49e1722b009375a5d3dc0e3386b74256 /Source/Core/DiscIO/CompressedBlob.cpp
parent2635e7d9eaf6f96463de0a75a0b5a07c274b2cb4 (diff)
DiscIO: Avoid zeroing buffer when compressing gcz.
This saves 6% time.
Diffstat (limited to 'Source/Core/DiscIO/CompressedBlob.cpp')
-rw-r--r--Source/Core/DiscIO/CompressedBlob.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/Source/Core/DiscIO/CompressedBlob.cpp b/Source/Core/DiscIO/CompressedBlob.cpp
index 6170c5ad07..61549e5bda 100644
--- a/Source/Core/DiscIO/CompressedBlob.cpp
+++ b/Source/Core/DiscIO/CompressedBlob.cpp
@@ -163,11 +163,19 @@ bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u
scrubbing = true;
}
+ z_stream z;
+ memset(&z, 0, sizeof(z));
+ if (deflateInit(&z, 9) != Z_OK)
+ return false;
+
File::IOFile inf(infile, "rb");
File::IOFile f(outfile, "wb");
if (!f || !inf)
+ {
+ deflateEnd(&z);
return false;
+ }
callback("Files opened, ready to compress.", 0, arg);
@@ -213,23 +221,20 @@ bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u
}
offsets[i] = position;
- // u64 start = i * header.block_size;
- // u64 size = header.block_size;
- std::fill(in_buf, in_buf + header.block_size, 0);
+
+ size_t read_bytes;
if (scrubbing)
- DiscScrubber::GetNextBlock(inf, in_buf);
+ read_bytes = DiscScrubber::GetNextBlock(inf, in_buf);
else
- inf.ReadBytes(in_buf, header.block_size);
- z_stream z;
- memset(&z, 0, sizeof(z));
- z.zalloc = Z_NULL;
- z.zfree = Z_NULL;
- z.opaque = Z_NULL;
+ inf.ReadArray(in_buf, header.block_size, &read_bytes);
+ if (read_bytes < header.block_size)
+ std::fill(in_buf + read_bytes, in_buf + header.block_size, 0);
+
+ int retval = deflateReset(&z);
z.next_in = in_buf;
z.avail_in = header.block_size;
z.next_out = out_buf;
z.avail_out = block_size;
- int retval = deflateInit(&z, 9);
if (retval != Z_OK)
{
@@ -258,8 +263,6 @@ bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u
position += comp_size;
num_compressed++;
}
-
- deflateEnd(&z);
}
header.compressed_data_size = position;
@@ -286,6 +289,8 @@ cleanup:
delete[] offsets;
delete[] hashes;
+ deflateEnd(&z);
+
DiscScrubber::Cleanup();
callback("Done compressing disc image.", 1.0f, arg);
return true;