Get rid of StreamBuffer::read_entire_contents and StreamBuffer::hash

This commit is contained in:
2023-10-18 14:32:12 -04:00
parent 3e8aa31a95
commit 6c2a27b274
4 changed files with 2 additions and 22 deletions

View File

@@ -136,7 +136,7 @@ eng::string AnimState::encode() const {
sb.write_bool(value.persistent);
sb.write_simple_dynamic(value);
}
return sb.read_entire_contents();
return eng::string(sb.view());
}
void AnimState::decode(std::string_view s) {

View File

@@ -100,7 +100,7 @@ public:
void send_lua_source(const util::LuaSourceVec &sv) {
StreamBuffer serial;
SourceDB::serialize_source(sv, &serial);
eng::string sstr = serial.read_entire_contents();
eng::string sstr(serial.view());
Invocation inv(Invocation::KIND_LUA_SOURCE, actor_id_, actor_id_, sstr);
send_invocation(inv);
}

View File

@@ -227,12 +227,6 @@ util::HashValue StreamBuffer::read_hashvalue() {
return util::HashValue(f,s);
}
eng::string StreamBuffer::read_entire_contents() {
eng::string result(read_cursor_, fill());
read_cursor_ = write_cursor_;
return result;
}
void StreamBuffer::overwrite_int8(int64_t write_count_after, int64_t vv) {
int8_t v = vv;
assert(int64_t(v) == vv);
@@ -328,13 +322,6 @@ bool StreamBuffer::contents_equal(const StreamBuffer *other) const {
return memcmp(read_cursor_, other->read_cursor_, len) == 0;
}
util::HashValue StreamBuffer::hash() const {
uint64_t hash1 = 0x82A7912E7893AC87;
uint64_t hash2 = 0x81D402740DE458F3;
SpookyHash::ChainHash128(read_cursor_, write_cursor_ - read_cursor_, &hash1, &hash2);
return std::make_pair(hash1, hash2);
}
int lua_writer_into_streambuffer(lua_State *L, const void* bytes, size_t sz, void* sbv) {
StreamBuffer *sb = (StreamBuffer *)sbv;
memcpy(sb->make_space(sz), bytes, sz);

View File

@@ -336,10 +336,6 @@ public:
void write_hashvalue(const util::HashValue &hv);
util::HashValue read_hashvalue();
// Read the entire contents of the buffer as a string.
//
eng::string read_entire_contents();
// Overwrite values previously written to the buffer.
//
// See the comment at the top of this file for an explanation.
@@ -382,9 +378,6 @@ public:
// Compare the contents of this streambuffer to another one.
bool contents_equal(const StreamBuffer *sb) const;
// Calculate a noncryptographic but good hash of what's in the buffer.
util::HashValue hash() const;
// Throw a StreamCorruption exception.
void raise_truncated() { throw StreamCorruption(); }
void raise_string_too_long() { throw StreamCorruption(); }