DiscIO: Avoid zeroing buffer when compressing gcz.
This saves 6% time.
This commit is contained in:
parent
2635e7d9ea
commit
f54bf81520
|
@ -163,11 +163,19 @@ bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u
|
||||||
scrubbing = true;
|
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 inf(infile, "rb");
|
||||||
File::IOFile f(outfile, "wb");
|
File::IOFile f(outfile, "wb");
|
||||||
|
|
||||||
if (!f || !inf)
|
if (!f || !inf)
|
||||||
|
{
|
||||||
|
deflateEnd(&z);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
callback("Files opened, ready to compress.", 0, arg);
|
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;
|
offsets[i] = position;
|
||||||
// u64 start = i * header.block_size;
|
|
||||||
// u64 size = header.block_size;
|
size_t read_bytes;
|
||||||
std::fill(in_buf, in_buf + header.block_size, 0);
|
|
||||||
if (scrubbing)
|
if (scrubbing)
|
||||||
DiscScrubber::GetNextBlock(inf, in_buf);
|
read_bytes = DiscScrubber::GetNextBlock(inf, in_buf);
|
||||||
else
|
else
|
||||||
inf.ReadBytes(in_buf, header.block_size);
|
inf.ReadArray(in_buf, header.block_size, &read_bytes);
|
||||||
z_stream z;
|
if (read_bytes < header.block_size)
|
||||||
memset(&z, 0, sizeof(z));
|
std::fill(in_buf + read_bytes, in_buf + header.block_size, 0);
|
||||||
z.zalloc = Z_NULL;
|
|
||||||
z.zfree = Z_NULL;
|
int retval = deflateReset(&z);
|
||||||
z.opaque = Z_NULL;
|
|
||||||
z.next_in = in_buf;
|
z.next_in = in_buf;
|
||||||
z.avail_in = header.block_size;
|
z.avail_in = header.block_size;
|
||||||
z.next_out = out_buf;
|
z.next_out = out_buf;
|
||||||
z.avail_out = block_size;
|
z.avail_out = block_size;
|
||||||
int retval = deflateInit(&z, 9);
|
|
||||||
|
|
||||||
if (retval != Z_OK)
|
if (retval != Z_OK)
|
||||||
{
|
{
|
||||||
|
@ -258,8 +263,6 @@ bool CompressFileToBlob(const std::string& infile, const std::string& outfile, u
|
||||||
position += comp_size;
|
position += comp_size;
|
||||||
num_compressed++;
|
num_compressed++;
|
||||||
}
|
}
|
||||||
|
|
||||||
deflateEnd(&z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
header.compressed_data_size = position;
|
header.compressed_data_size = position;
|
||||||
|
@ -286,6 +289,8 @@ cleanup:
|
||||||
delete[] offsets;
|
delete[] offsets;
|
||||||
delete[] hashes;
|
delete[] hashes;
|
||||||
|
|
||||||
|
deflateEnd(&z);
|
||||||
|
|
||||||
DiscScrubber::Cleanup();
|
DiscScrubber::Cleanup();
|
||||||
callback("Done compressing disc image.", 1.0f, arg);
|
callback("Done compressing disc image.", 1.0f, arg);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -124,24 +124,27 @@ bool SetupScrub(const std::string& filename, int block_size)
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetNextBlock(File::IOFile& in, u8* buffer)
|
size_t GetNextBlock(File::IOFile& in, u8* buffer)
|
||||||
{
|
{
|
||||||
u64 CurrentOffset = m_BlockCount * m_BlockSize;
|
u64 CurrentOffset = m_BlockCount * m_BlockSize;
|
||||||
u64 i = CurrentOffset / CLUSTER_SIZE;
|
u64 i = CurrentOffset / CLUSTER_SIZE;
|
||||||
|
|
||||||
|
size_t ReadBytes = 0;
|
||||||
if (m_isScrubbing && m_FreeTable[i])
|
if (m_isScrubbing && m_FreeTable[i])
|
||||||
{
|
{
|
||||||
DEBUG_LOG(DISCIO, "Freeing 0x%016" PRIx64, CurrentOffset);
|
DEBUG_LOG(DISCIO, "Freeing 0x%016" PRIx64, CurrentOffset);
|
||||||
std::fill(buffer, buffer + m_BlockSize, 0xFF);
|
std::fill(buffer, buffer + m_BlockSize, 0xFF);
|
||||||
in.Seek(m_BlockSize, SEEK_CUR);
|
in.Seek(m_BlockSize, SEEK_CUR);
|
||||||
|
ReadBytes = m_BlockSize;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUG_LOG(DISCIO, "Used 0x%016" PRIx64, CurrentOffset);
|
DEBUG_LOG(DISCIO, "Used 0x%016" PRIx64, CurrentOffset);
|
||||||
in.ReadBytes(buffer, m_BlockSize);
|
in.ReadArray(buffer, m_BlockSize, &ReadBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_BlockCount++;
|
m_BlockCount++;
|
||||||
|
return ReadBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cleanup()
|
void Cleanup()
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace DiscScrubber
|
||||||
{
|
{
|
||||||
|
|
||||||
bool SetupScrub(const std::string& filename, int block_size);
|
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();
|
void Cleanup();
|
||||||
|
|
||||||
} // namespace DiscScrubber
|
} // namespace DiscScrubber
|
||||||
|
|
Loading…
Reference in New Issue