refactor: use DataStream::clear in ::read and ::ignore

When `DataStream` is fully consumed, both `read()` and `ignore()` reset it to an empty state by clearing the backing buffer and resetting the read position.

Call `clear()` in both places instead of open-coding the same state transition.
This keeps the behavior unchanged while documenting the fully-consumed reset in one place.

Remove the unused `Compact()` method as well - it has been unused for a long time and can be added back if it is ever needed.
This commit is contained in:
Lőrinc
2025-12-30 13:45:56 +01:00
parent d3a40dd9de
commit 61d678a6e3

View File

@@ -206,12 +206,6 @@ public:
value_type* data() { return vch.data() + m_read_pos; }
const value_type* data() const { return vch.data() + m_read_pos; }
inline void Compact()
{
vch.erase(vch.begin(), vch.begin() + m_read_pos);
m_read_pos = 0;
}
bool Rewind(std::optional<size_type> n = std::nullopt)
{
// Total rewind if no size is passed
@@ -243,8 +237,8 @@ public:
}
memcpy(dst.data(), &vch[m_read_pos], dst.size());
if (next_read_pos.value() == vch.size()) {
m_read_pos = 0;
vch.clear();
// If fully consumed, reset to empty state.
clear();
return;
}
m_read_pos = next_read_pos.value();
@@ -258,8 +252,8 @@ public:
throw std::ios_base::failure("DataStream::ignore(): end of data");
}
if (next_read_pos.value() == vch.size()) {
m_read_pos = 0;
vch.clear();
// If all bytes are ignored, reset to empty state.
clear();
return;
}
m_read_pos = next_read_pos.value();