Skip to content

Commit

Permalink
Define variables more close to its use place in types (#1675)
Browse files Browse the repository at this point in the history
Co-authored-by: Binbin <[email protected]>
  • Loading branch information
PragmaTwice and enjoy-binbin authored Aug 15, 2023
1 parent 5cdbb19 commit b1bc678
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/types/redis_bitmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions src/types/redis_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions src/types/redis_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit b1bc678

Please sign in to comment.