DiscIO: Avoid zeroing buffer when compressing gcz.

This saves 6% time.
This commit is contained in:
Unknown W. Brackets 2014-11-27 08:57:49 -08:00
parent 2635e7d9ea
commit f54bf81520
3 changed files with 24 additions and 16 deletions

View File

@ -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;

View File

@ -124,24 +124,27 @@ bool SetupScrub(const std::string& filename, int block_size)
return success;
}
void GetNextBlock(File::IOFile& in, u8* buffer)
size_t GetNextBlock(File::IOFile& in, u8* buffer)
{
u64 CurrentOffset = m_BlockCount * m_BlockSize;
u64 i = CurrentOffset / CLUSTER_SIZE;
size_t ReadBytes = 0;
if (m_isScrubbing && m_FreeTable[i])
{
DEBUG_LOG(DISCIO, "Freeing 0x%016" PRIx64, CurrentOffset);
std::fill(buffer, buffer + m_BlockSize, 0xFF);
in.Seek(m_BlockSize, SEEK_CUR);
ReadBytes = m_BlockSize;
}
else
{
DEBUG_LOG(DISCIO, "Used 0x%016" PRIx64, CurrentOffset);
in.ReadBytes(buffer, m_BlockSize);
in.ReadArray(buffer, m_BlockSize, &ReadBytes);
}
m_BlockCount++;
return ReadBytes;
}
void Cleanup()

View File

@ -25,7 +25,7 @@ namespace DiscScrubber
{
bool SetupScrub(const std::string& filename, int block_size);
void GetNextBlock(File::IOFile& in, u8* buffer);
size_t GetNextBlock(File::IOFile& in, u8* buffer);
void Cleanup();
} // namespace DiscScrubber