@@ -89,8 +89,8 @@ class CompactObj {
8989
9090 enum MaskBit {
9191 REF_BIT = 1 ,
92- EXPIRE_BIT = 2 ,
93- FLAG_BIT = 4 ,
92+ EXPIRE_BIT = 2 , // Mark objects that have expiry timestamp assigned.
93+ FLAG_BIT = 4 , // Used to mark keys that have memcache flags assigned.
9494
9595 // ascii encoding is not an injective function. it compresses 8 bytes to 7 but also 7 to 7.
9696 // therefore, in order to know the original length we introduce 2 flags that
@@ -266,14 +266,15 @@ class CompactObj {
266266 bool IsExternal () const {
267267 return taglen_ == EXTERNAL_TAG;
268268 }
269+
269270 void SetExternal (size_t offset, size_t sz);
270271 std::pair<size_t , size_t > GetExternalPtr () const ;
271272
272273 // In case this object a single blob, returns number of bytes allocated on heap
273274 // for that blob. Otherwise returns 0.
274275 size_t MallocUsed () const ;
275276
276- // Resets the object to empty state.
277+ // Resets the object to empty state (string) .
277278 void Reset ();
278279
279280 bool IsInline () const {
@@ -346,9 +347,9 @@ class CompactObj {
346347 //
347348 static_assert (sizeof (u_) == 16 , " " );
348349
349- // Maybe it's possible to merge those 2 together and gain another byte
350- // but lets postpone it to 2023.
351350 mutable uint8_t mask_ = 0 ;
351+
352+ // We currently reserve 5 bits for tags and 3 bits for extending the mask. currently reserved.
352353 uint8_t taglen_ = 0 ;
353354};
354355
@@ -362,4 +363,45 @@ inline bool CompactObj::operator==(std::string_view sv) const {
362363 return EqualNonInline (sv);
363364}
364365
366+ class CompactObjectView {
367+ public:
368+ CompactObjectView (const CompactObj& src) : obj_(src.AsRef()) {
369+ }
370+ CompactObjectView (const CompactObjectView& o) : obj_(o.obj_.AsRef()) {
371+ }
372+ CompactObjectView (CompactObjectView&& o) = default ;
373+
374+ operator CompactObj () const {
375+ return obj_.AsRef ();
376+ }
377+
378+ const CompactObj* operator ->() const {
379+ return &obj_;
380+ }
381+
382+ bool operator ==(const CompactObjectView& o) const {
383+ return obj_ == o.obj_ ;
384+ }
385+
386+ uint64_t Hash () const {
387+ return obj_.HashCode ();
388+ }
389+
390+ CompactObjectView& operator =(const CompactObjectView& o) {
391+ obj_ = o.obj_ .AsRef ();
392+ return *this ;
393+ }
394+
395+ bool defined () const {
396+ return obj_.IsRef ();
397+ }
398+
399+ void Reset () {
400+ obj_.Reset ();
401+ }
402+
403+ private:
404+ CompactObj obj_;
405+ };
406+
365407} // namespace dfly
0 commit comments