Skip to content

Commit

Permalink
opt: Slightly less allocations in OpaqueObjLoader::CreateHMap (#1227)
Browse files Browse the repository at this point in the history
Moves the temporary variable outside the loop so we can reuse the buffer.

Signed-off-by: Roy Jacobson <roy@dragonflydb.io>
  • Loading branch information
royjacobson committed May 17, 2023
1 parent 9ff8cdf commit a1a8acb
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/server/rdb_load.cc
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,13 @@ void RdbLoaderBase::OpaqueObjLoader::CreateHMap(const LoadTrace* ltrace) {
StringMap* string_map = new StringMap;

auto cleanup = absl::MakeCleanup([&] { delete string_map; });
std::string key;
string_map->Reserve(len);
for (const auto& seg : ltrace->arr) {
for (size_t i = 0; i < seg.size(); i += 2) {
// ToSV may reference an internal buffer, therefore we can use only before the
// next call to ToSV. To workaround, I copy the key to string.
string key(ToSV(seg[i].rdb_var));
// next call to ToSV. To workaround, copy the key locally.
key = ToSV(seg[i].rdb_var);
string_view val = ToSV(seg[i + 1].rdb_var);

if (ec_)
Expand Down

0 comments on commit a1a8acb

Please sign in to comment.