@@ -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
574559inline 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
584569std::string_view ObjTypeToString (CompactObjType type);
0 commit comments