This is an automated email from the ASF dual-hosted git repository.
twice pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new b1bc6780 Define variables more close to its use place in types (#1675)
b1bc6780 is described below
commit b1bc67802f5eb84ef1a8f5951ee31fa33ea97a30
Author: Twice <[email protected]>
AuthorDate: Tue Aug 15 15:32:44 2023 +0800
Define variables more close to its use place in types (#1675)
Co-authored-by: Binbin <[email protected]>
---
src/types/redis_bitmap.cc | 4 +---
src/types/redis_list.cc | 5 ++---
src/types/redis_string.cc | 6 ++----
3 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/src/types/redis_bitmap.cc b/src/types/redis_bitmap.cc
index 19db2209..501ca7a1 100644
--- a/src/types/redis_bitmap.cc
+++ b/src/types/redis_bitmap.cc
@@ -106,8 +106,6 @@ rocksdb::Status Bitmap::GetString(const Slice &user_key,
const uint32_t max_btos
}
value->assign(metadata.size, 0);
- std::string fragment;
- fragment.reserve(kBitmapSegmentBytes * 2);
std::string prefix_key = InternalKey(ns_key, "", metadata.version,
storage_->IsSlotIdEncoded()).Encode();
rocksdb::ReadOptions read_options = storage_->DefaultScanOptions();
@@ -122,7 +120,7 @@ rocksdb::Status Bitmap::GetString(const Slice &user_key,
const uint32_t max_btos
return rocksdb::Status::InvalidArgument(parse_result.Msg());
}
uint32_t frag_index = *parse_result;
- fragment = iter->value().ToString();
+ std::string fragment = iter->value().ToString();
// To be compatible with data written before the commit d603b0e(#338)
// and avoid returning extra null char after expansion.
uint32_t valid_size = std::min(
diff --git a/src/types/redis_list.cc b/src/types/redis_list.cc
index 688da498..34db5be0 100644
--- a/src/types/redis_list.cc
+++ b/src/types/redis_list.cc
@@ -294,7 +294,6 @@ rocksdb::Status List::Insert(const Slice &user_key, const
Slice &pivot, const Sl
{std::to_string(kRedisCmdLInsert), before ? "1" :
"0", pivot.ToString(), elem.ToString()});
batch->PutLogData(log_data.Encode());
- std::string to_update_key;
uint64_t left_part_len = pivot_index - metadata.head + (before ? 0 : 1);
uint64_t right_part_len = metadata.tail - 1 - pivot_index + (before ? 1 : 0);
bool reversed = left_part_len <= right_part_len;
@@ -308,12 +307,12 @@ rocksdb::Status List::Insert(const Slice &user_key, const
Slice &pivot, const Sl
for (; iter->Valid() && iter->key().starts_with(prefix); !reversed ?
iter->Next() : iter->Prev()) {
buf.clear();
PutFixed64(&buf, reversed ? --pivot_index : ++pivot_index);
- to_update_key = InternalKey(ns_key, buf, metadata.version,
storage_->IsSlotIdEncoded()).Encode();
+ std::string to_update_key = InternalKey(ns_key, buf, metadata.version,
storage_->IsSlotIdEncoded()).Encode();
batch->Put(to_update_key, iter->value());
}
buf.clear();
PutFixed64(&buf, new_elem_index);
- to_update_key = InternalKey(ns_key, buf, metadata.version,
storage_->IsSlotIdEncoded()).Encode();
+ std::string to_update_key = InternalKey(ns_key, buf, metadata.version,
storage_->IsSlotIdEncoded()).Encode();
batch->Put(to_update_key, elem);
if (reversed) {
diff --git a/src/types/redis_string.cc b/src/types/redis_string.cc
index a5db05de..844e1ca9 100644
--- a/src/types/redis_string.cc
+++ b/src/types/redis_string.cc
@@ -285,7 +285,6 @@ rocksdb::Status String::SetRange(const std::string
&user_key, size_t offset, con
}
rocksdb::Status String::IncrBy(const std::string &user_key, int64_t increment,
int64_t *new_value) {
- std::string value;
std::string ns_key = AppendNamespacePrefix(user_key);
LockGuard guard(storage_->GetLockManager(), ns_key);
@@ -298,7 +297,7 @@ rocksdb::Status String::IncrBy(const std::string &user_key,
int64_t increment, i
}
size_t offset = Metadata::GetOffsetAfterExpire(raw_value[0]);
- value = raw_value.substr(offset);
+ std::string value = raw_value.substr(offset);
int64_t n = 0;
if (!value.empty()) {
auto parse_result = ParseInt<int64_t>(value, 10);
@@ -323,7 +322,6 @@ rocksdb::Status String::IncrBy(const std::string &user_key,
int64_t increment, i
}
rocksdb::Status String::IncrByFloat(const std::string &user_key, double
increment, double *new_value) {
- std::string value;
std::string ns_key = AppendNamespacePrefix(user_key);
LockGuard guard(storage_->GetLockManager(), ns_key);
std::string raw_value;
@@ -335,7 +333,7 @@ rocksdb::Status String::IncrByFloat(const std::string
&user_key, double incremen
metadata.Encode(&raw_value);
}
size_t offset = Metadata::GetOffsetAfterExpire(raw_value[0]);
- value = raw_value.substr(offset);
+ std::string value = raw_value.substr(offset);
double n = 0;
if (!value.empty()) {
auto n_stat = ParseFloat(value);