IOStreams: Remove reinterpret_casts where applicable

We can simply make use of writeBytes() where applicable, which does it
for us, which makes the code a slight bit less verbose.
This commit is contained in:
Lioncash 2019-11-08 18:55:10 -05:00
parent 3894c0539e
commit 95a0b0e559
1 changed files with 14 additions and 10 deletions

View File

@ -78,7 +78,7 @@ void CBitStreamWriter::WriteEncoded(u32 val, u32 bitCount) {
/* Write out 32-bits */ /* Write out 32-bits */
x14_val = hecl::SBig(x14_val); x14_val = hecl::SBig(x14_val);
writeUBytes(reinterpret_cast<u8*>(&x14_val), 4); writeBytes(&x14_val, sizeof(x14_val));
/* Cache remaining bits */ /* Cache remaining bits */
x18_bitOffset = 0x20 + shiftAmt; x18_bitOffset = 0x20 + shiftAmt;
@ -94,15 +94,19 @@ void CBitStreamWriter::WriteEncoded(u32 val, u32 bitCount) {
} }
void CBitStreamWriter::Flush() { void CBitStreamWriter::Flush() {
if (x18_bitOffset < 0x20) { if (x18_bitOffset >= 0x20) {
auto pos = std::div(0x20 - x18_bitOffset, 8); return;
if (pos.rem)
++pos.quot;
x14_val = hecl::SBig(x14_val);
writeUBytes(reinterpret_cast<u8*>(&x14_val), pos.quot);
x18_bitOffset = 0x20;
x14_val = 0;
} }
auto pos = std::div(0x20 - s32(x18_bitOffset), 8);
if (pos.rem != 0) {
++pos.quot;
}
x14_val = hecl::SBig(x14_val);
writeBytes(&x14_val, pos.quot);
x18_bitOffset = 0x20;
x14_val = 0;
} }
class CZipSupport { class CZipSupport {
@ -123,7 +127,7 @@ CZipInputStream::CZipInputStream(std::unique_ptr<CInputStream>&& strm)
CZipInputStream::~CZipInputStream() { inflateEnd(&x30_zstrm); } CZipInputStream::~CZipInputStream() { inflateEnd(&x30_zstrm); }
atUint64 CZipInputStream::readUBytesToBuf(void* buf, atUint64 len) { atUint64 CZipInputStream::readUBytesToBuf(void* buf, atUint64 len) {
x30_zstrm.next_out = (Bytef*)buf; x30_zstrm.next_out = static_cast<Bytef*>(buf);
x30_zstrm.avail_out = len; x30_zstrm.avail_out = len;
x30_zstrm.total_out = 0; x30_zstrm.total_out = 0;
while (x30_zstrm.avail_out != 0) { while (x30_zstrm.avail_out != 0) {