mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 02:15:45 +02:00
fix: remove code duplicate in GetSlice (#5079)
* fix: remove code duplicate in GetSlice * Update src/core/compact_object.cc Co-authored-by: Kostas Kyrimis <kostas@dragonflydb.io> Signed-off-by: Roman Gershman <romange@gmail.com> * Update src/core/compact_object.cc Signed-off-by: Kostas Kyrimis <kostaskyrim@gmail.com> --------- Signed-off-by: Roman Gershman <romange@gmail.com> Signed-off-by: Kostas Kyrimis <kostaskyrim@gmail.com> Co-authored-by: Kostas Kyrimis <kostas@dragonflydb.io>
This commit is contained in:
parent
ad5aa66350
commit
1e40e3aa9b
1 changed files with 5 additions and 40 deletions
|
@ -1008,23 +1008,15 @@ void CompactObj::AppendString(std::string_view str) {
|
||||||
u_.r_obj.AppendString(str, tl.local_mr);
|
u_.r_obj.AppendString(str, tl.local_mr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: to simplify this code using GetString(char*) variant.
|
|
||||||
string_view CompactObj::GetSlice(string* scratch) const {
|
string_view CompactObj::GetSlice(string* scratch) const {
|
||||||
CHECK(!IsExternal());
|
CHECK(!IsExternal());
|
||||||
|
|
||||||
|
if (mask_bits_.encoding) {
|
||||||
|
GetString(scratch);
|
||||||
|
return *scratch;
|
||||||
|
}
|
||||||
|
|
||||||
if (IsInline()) {
|
if (IsInline()) {
|
||||||
if (mask_bits_.encoding) {
|
|
||||||
size_t decoded_len = taglen_ + 2;
|
|
||||||
|
|
||||||
// must be this because we either shortened 17 or 18.
|
|
||||||
DCHECK_EQ(mask_bits_.encoding, ASCII2_ENC);
|
|
||||||
DCHECK_EQ(decoded_len, ascii_len(taglen_));
|
|
||||||
|
|
||||||
scratch->resize(decoded_len);
|
|
||||||
detail::ascii_unpack(to_byte(u_.inline_str), decoded_len, scratch->data());
|
|
||||||
return *scratch;
|
|
||||||
}
|
|
||||||
|
|
||||||
return string_view{u_.inline_str, taglen_};
|
return string_view{u_.inline_str, taglen_};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1035,33 +1027,6 @@ string_view CompactObj::GetSlice(string* scratch) const {
|
||||||
return *scratch;
|
return *scratch;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mask_bits_.encoding) {
|
|
||||||
if (taglen_ == ROBJ_TAG) {
|
|
||||||
CHECK_EQ(OBJ_STRING, u_.r_obj.type());
|
|
||||||
DCHECK_EQ(OBJ_ENCODING_RAW, u_.r_obj.encoding());
|
|
||||||
size_t decoded_len = DecodedLen(u_.r_obj.Size());
|
|
||||||
scratch->resize(decoded_len);
|
|
||||||
detail::ascii_unpack_simd(to_byte(u_.r_obj.inner_obj()), decoded_len, scratch->data());
|
|
||||||
} else if (taglen_ == SMALL_TAG) {
|
|
||||||
size_t decoded_len = DecodedLen(u_.small_str.size());
|
|
||||||
scratch->resize(decoded_len);
|
|
||||||
string_view slices[2];
|
|
||||||
|
|
||||||
unsigned num = u_.small_str.GetV(slices);
|
|
||||||
DCHECK_EQ(2u, num);
|
|
||||||
std::string tmp(decoded_len, ' ');
|
|
||||||
char* next = tmp.data();
|
|
||||||
memcpy(next, slices[0].data(), slices[0].size());
|
|
||||||
next += slices[0].size();
|
|
||||||
memcpy(next, slices[1].data(), slices[1].size());
|
|
||||||
detail::ascii_unpack_simd(reinterpret_cast<uint8_t*>(tmp.data()), decoded_len,
|
|
||||||
scratch->data());
|
|
||||||
} else {
|
|
||||||
LOG(FATAL) << "Unsupported tag " << int(taglen_);
|
|
||||||
}
|
|
||||||
return *scratch;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no encoding.
|
// no encoding.
|
||||||
if (taglen_ == ROBJ_TAG) {
|
if (taglen_ == ROBJ_TAG) {
|
||||||
CHECK_EQ(OBJ_STRING, u_.r_obj.type());
|
CHECK_EQ(OBJ_STRING, u_.r_obj.type());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue