mirror of https://github.com/libAthena/athena.git
Merge pull request #44 from lioncash/simplify
IStreamReader/IStreamWriter: Simplify buffer functions where applicable
This commit is contained in:
commit
4af15d46c9
|
@ -103,10 +103,9 @@ public:
|
||||||
* @return The buffer at the current position from the given length.
|
* @return The buffer at the current position from the given length.
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<atInt8[]> readBytes(atUint64 length) {
|
std::unique_ptr<atInt8[]> readBytes(atUint64 length) {
|
||||||
atInt8* buf = new atInt8[length];
|
auto buf = std::make_unique<atInt8[]>(length);
|
||||||
memset(buf, 0, length);
|
readUBytesToBuf(buf.get(), length);
|
||||||
readUBytesToBuf(buf, length);
|
return buf;
|
||||||
return std::unique_ptr<atInt8[]>(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Reads a byte at the current position and advances the current position.
|
/** @brief Reads a byte at the current position and advances the current position.
|
||||||
|
@ -114,10 +113,9 @@ public:
|
||||||
* @return The buffer at the current position from the given length.
|
* @return The buffer at the current position from the given length.
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<atUint8[]> readUBytes(atUint64 length) {
|
std::unique_ptr<atUint8[]> readUBytes(atUint64 length) {
|
||||||
atUint8* buf = new atUint8[length];
|
auto buf = std::make_unique<atUint8[]>(length);
|
||||||
memset(buf, 0, length);
|
readUBytesToBuf(buf.get(), length);
|
||||||
readUBytesToBuf(buf, length);
|
return buf;
|
||||||
return std::unique_ptr<atUint8[]>(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @brief Attempts to read a fixed length of data into a pre-allocated buffer.
|
/** @brief Attempts to read a fixed length of data into a pre-allocated buffer.
|
||||||
|
|
|
@ -977,9 +977,8 @@ public:
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::unique_ptr<atUint8[]> tmp(new atUint8[length]);
|
const std::vector<atUint8> tmp(length, val);
|
||||||
memset(tmp.get(), val, length);
|
writeUBytes(tmp.data(), length);
|
||||||
writeUBytes(tmp.get(), length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void fill(atInt8 val, atUint64 length) { fill((atUint8)val, length); }
|
void fill(atInt8 val, atUint64 length) { fill((atUint8)val, length); }
|
||||||
|
|
Loading…
Reference in New Issue