From 28602d36254263127c0e1b90334614abc1ee0c83 Mon Sep 17 00:00:00 2001 From: wzk784533 Date: Sat, 11 Jul 2020 13:44:11 +0800 Subject: [PATCH] avoid unnecessary memory copy --- db/builder.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/db/builder.cc b/db/builder.cc index 943e857..fe5cde1 100644 --- a/db/builder.cc +++ b/db/builder.cc @@ -30,11 +30,14 @@ Status BuildTable(const std::string& dbname, Env* env, const Options& options, TableBuilder* builder = new TableBuilder(options, file); meta->smallest.DecodeFrom(iter->key()); + Slice key; for (; iter->Valid(); iter->Next()) { - Slice key = iter->key(); - meta->largest.DecodeFrom(key); + key = iter->key(); builder->Add(key, iter->value()); } + if(!key.empty()) { + meta->largest.DecodeFrom(key); + } // Finish and check for builder errors s = builder->Finish();