From 6c2a27b274427931fcdc2afcab42b89ebe5db8c0 Mon Sep 17 00:00:00 2001 From: jyelon Date: Wed, 18 Oct 2023 14:32:12 -0400 Subject: [PATCH] Get rid of StreamBuffer::read_entire_contents and StreamBuffer::hash --- luprex/cpp/core/animqueue.cpp | 2 +- luprex/cpp/core/lpxclient.cpp | 2 +- luprex/cpp/core/streambuffer.cpp | 13 ------------- luprex/cpp/core/streambuffer.hpp | 7 ------- 4 files changed, 2 insertions(+), 22 deletions(-) diff --git a/luprex/cpp/core/animqueue.cpp b/luprex/cpp/core/animqueue.cpp index 079a2bf4..45162d7c 100644 --- a/luprex/cpp/core/animqueue.cpp +++ b/luprex/cpp/core/animqueue.cpp @@ -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) { diff --git a/luprex/cpp/core/lpxclient.cpp b/luprex/cpp/core/lpxclient.cpp index 4a70d30d..3471df55 100644 --- a/luprex/cpp/core/lpxclient.cpp +++ b/luprex/cpp/core/lpxclient.cpp @@ -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); } diff --git a/luprex/cpp/core/streambuffer.cpp b/luprex/cpp/core/streambuffer.cpp index 395fbd5a..0a8374e9 100644 --- a/luprex/cpp/core/streambuffer.cpp +++ b/luprex/cpp/core/streambuffer.cpp @@ -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); diff --git a/luprex/cpp/core/streambuffer.hpp b/luprex/cpp/core/streambuffer.hpp index b9fbd376..4d91acaf 100644 --- a/luprex/cpp/core/streambuffer.hpp +++ b/luprex/cpp/core/streambuffer.hpp @@ -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(); }