Skip to content

Commit e32a4ed

Browse files
authored
chore(core): Remove some unused CompactObj code (#6141)
1 parent a0e5c83 commit e32a4ed

File tree

2 files changed

+23
-39
lines changed

2 files changed

+23
-39
lines changed

src/core/compact_object.cc

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -781,15 +781,13 @@ CompactObj::~CompactObj() {
781781
CompactObj& CompactObj::operator=(CompactObj&& o) noexcept {
782782
DCHECK(&o != this);
783783

784-
SetMeta(o.taglen_, o.mask_); // Frees underlying resources if needed.
784+
SetMeta(o.taglen_, o.mask_); // frees own previous resources
785785
memcpy(&u_, &o.u_, sizeof(u_));
786+
huffman_domain_ = o.huffman_domain_;
786787

787-
tagbyte_ = o.tagbyte_;
788-
789-
// SetMeta deallocates the object and we only want reset it.
790-
o.tagbyte_ = 0;
788+
o.taglen_ = 0; // forget all data
789+
o.huffman_domain_ = 0;
791790
o.mask_ = 0;
792-
793791
return *this;
794792
}
795793

@@ -1268,7 +1266,8 @@ void CompactObj::Reset() {
12681266
if (HasAllocated()) {
12691267
Free();
12701268
}
1271-
tagbyte_ = 0;
1269+
taglen_ = 0;
1270+
huffman_domain_ = 0;
12721271
mask_ = 0;
12731272
}
12741273

@@ -1380,13 +1379,11 @@ bool CompactObj::operator==(const CompactObj& o) const {
13801379
return memcmp(u_.inline_str, o.u_.inline_str, taglen_) == 0;
13811380
}
13821381

1383-
bool CompactObj::EqualNonInline(std::string_view sv) const {
1382+
bool CompactObj::CmpNonInline(std::string_view sv) const {
1383+
DCHECK_GT(taglen_, kInlineLen);
13841384
switch (taglen_) {
1385-
case INT_TAG: {
1386-
absl::AlphaNum an(u_.ival);
1387-
return sv == an.Piece();
1388-
}
1389-
1385+
case INT_TAG:
1386+
return absl::AlphaNum(u_.ival).Piece() == sv;
13901387
case ROBJ_TAG:
13911388
return u_.r_obj.Equal(sv);
13921389
case SMALL_TAG:
@@ -1398,6 +1395,8 @@ bool CompactObj::EqualNonInline(std::string_view sv) const {
13981395
}
13991396

14001397
bool CompactObj::CmpEncoded(string_view sv) const {
1398+
DCHECK(mask_bits_.encoding);
1399+
14011400
if (mask_bits_.encoding == HUFFMAN_ENC) {
14021401
size_t sz = Size();
14031402
if (sv.size() != sz)

src/core/compact_object.h

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ class CompactObj {
158158
bool is_key_;
159159
};
160160

161-
using PrefixArray = std::vector<std::string_view>;
162161
using MemoryResource = detail::RobjWrapper::MemoryResource;
163162

164163
// Different representations of external values
@@ -167,14 +166,14 @@ class CompactObj {
167166
SERIALIZED_MAP // OBJ_HASH, Serialized map
168167
};
169168

170-
CompactObj() { // By default - empty string.
169+
CompactObj() : taglen_{0}, huffman_domain_{0} { // default - empty string
171170
}
172171

173-
explicit CompactObj(std::string_view str, bool is_key) {
172+
explicit CompactObj(std::string_view str, bool is_key) : CompactObj() {
174173
SetString(str, is_key);
175174
}
176175

177-
CompactObj(CompactObj&& cs) noexcept {
176+
CompactObj(CompactObj&& cs) noexcept : CompactObj() {
178177
operator=(std::move(cs));
179178
};
180179

@@ -192,7 +191,8 @@ class CompactObj {
192191
CompactObj AsRef() const {
193192
CompactObj res;
194193
memcpy(&res.u_, &u_, sizeof(u_));
195-
res.tagbyte_ = tagbyte_;
194+
res.taglen_ = taglen_;
195+
res.huffman_domain_ = huffman_domain_;
196196
res.mask_ = mask_;
197197
res.mask_bits_.ref = 1;
198198

@@ -395,10 +395,6 @@ class CompactObj {
395395

396396
uint8_t GetFirstByte() const;
397397

398-
static constexpr unsigned InlineLen() {
399-
return kInlineLen;
400-
}
401-
402398
struct Stats {
403399
size_t small_string_bytes = 0;
404400
uint64_t huff_encode_total = 0, huff_encode_success = 0;
@@ -449,12 +445,11 @@ class CompactObj {
449445
private:
450446
void EncodeString(std::string_view str, bool is_key);
451447

452-
bool EqualNonInline(std::string_view sv) const;
453-
454448
// Requires: HasAllocated() - true.
455449
void Free();
456450

457451
bool CmpEncoded(std::string_view sv) const;
452+
bool CmpNonInline(std::string_view sv) const;
458453

459454
void SetMeta(uint8_t taglen, uint8_t mask = 0) {
460455
if (HasAllocated()) {
@@ -514,10 +509,7 @@ class CompactObj {
514509
bool DefragIfNeeded(PageUsage* page_usage);
515510
};
516511

517-
// My main data structure. Union of representations.
518-
// RobjWrapper is kInlineLen=16 bytes, so we employ SSO of that size via inline_str.
519-
// In case of int values, we waste 8 bytes. I am assuming it's ok and it's not the data type
520-
// with biggest memory usage.
512+
// Union of different representations
521513
union U {
522514
char inline_str[kInlineLen];
523515

@@ -534,7 +526,6 @@ class CompactObj {
534526
}
535527
} u_;
536528

537-
//
538529
static_assert(sizeof(u_) == 16);
539530

540531
union {
@@ -560,15 +551,9 @@ class CompactObj {
560551
} mask_bits_;
561552
};
562553

563-
// We currently reserve 5 bits for tags and 3 bits for extending the mask. currently reserved.
564-
union {
565-
uint8_t tagbyte_ = 0;
566-
struct {
567-
uint8_t taglen_ : 5;
568-
uint8_t huffman_domain_ : 1; // value from HuffmanDomain enum.
569-
uint8_t reserved : 2;
570-
};
571-
};
554+
// TODO: use c++20 bitfield initializers
555+
uint8_t taglen_ : 5; // Either length of inline string or tag of type
556+
uint8_t huffman_domain_ : 1; // Value from HuffmanDomain enum. TODO: replace as is_key
572557
};
573558

574559
inline bool CompactObj::operator==(std::string_view sv) const {
@@ -578,7 +563,7 @@ inline bool CompactObj::operator==(std::string_view sv) const {
578563
if (IsInline()) {
579564
return std::string_view{u_.inline_str, taglen_} == sv;
580565
}
581-
return EqualNonInline(sv);
566+
return CmpNonInline(sv);
582567
}
583568

584569
std::string_view ObjTypeToString(CompactObjType type);

0 commit comments

Comments
 (0)