Skip to content

Commit 7c73931

Browse files
committed
fix merge and refactor smallstr function
1 parent 5b2a652 commit 7c73931

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

src/core/compact_object.cc

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,8 +1466,7 @@ bool CompactObj::CmpEncoded(string_view sv) const {
14661466
// has only 9-10 bytes in its inline prefix storage.
14671467
DCHECK_GT(sv.size(), 16u); // we would not be in SMALL_TAG, otherwise.
14681468

1469-
string_view slice[2];
1470-
u_.small_str.Get(slice);
1469+
auto slice = u_.small_str.Get();
14711470
DCHECK_LT(slice[0].size(), 14u);
14721471

14731472
uint8_t tmpbuf[14];
@@ -1600,12 +1599,7 @@ std::array<std::string_view, 2> CompactObj::GetRawString() const {
16001599
}
16011600

16021601
if (taglen_ == SMALL_TAG) {
1603-
std::string_view arr[2];
1604-
u_.small_str.GetV(arr);
1605-
std::array<std::string_view, 2> out; // TODO: use c++ 20 to_array
1606-
out[0] = arr[0];
1607-
out[1] = arr[1];
1608-
return out;
1602+
return u_.small_str.Get();
16091603
}
16101604

16111605
LOG(FATAL) << "Unsupported tag for GetRawString(): " << int(taglen_);

src/core/small_string.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,11 @@ bool SmallString::Equal(const SmallString& os) const {
107107
if (size_ != os.size_)
108108
return false;
109109

110-
string_view me[2], other[2];
111-
Get(me);
112-
os.Get(other);
113-
114-
return me[0] == other[0] && me[1] == other[1];
110+
return Get() == os.Get();
115111
}
116112

117113
uint64_t SmallString::HashCode() const {
118-
string_view slice[2];
119-
Get(slice);
114+
array<string_view, 2> slice = Get();
120115

121116
XXH3_state_t* state = tl.xxh_state.get();
122117
XXH3_64bits_reset_withSeed(state, kHashSeed);
@@ -126,17 +121,18 @@ uint64_t SmallString::HashCode() const {
126121
return XXH3_64bits_digest(state);
127122
}
128123

129-
void SmallString::Get(string_view dest[2]) const {
124+
array<string_view, 2> SmallString::Get() const {
130125
DCHECK(size_);
131126

127+
array<string_view, 2> dest;
132128
dest[0] = string_view{prefix_, kPrefLen};
133129
uint8_t* ptr = tl.seg_alloc->Translate(small_ptr_);
134130
dest[1] = string_view{reinterpret_cast<char*>(ptr), size_ - kPrefLen};
131+
return dest;
135132
}
136133

137134
void SmallString::Get(char* out) const {
138-
string_view strs[2];
139-
Get(strs);
135+
auto strs = Get();
140136
memcpy(out, strs[0].data(), strs[0].size());
141137
memcpy(out + strs[0].size(), strs[1].data(), strs[1].size());
142138
}

src/core/small_string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SmallString {
3131
uint64_t HashCode() const;
3232
uint16_t MallocUsed() const;
3333

34-
void Get(std::string_view dest[2]) const;
34+
std::array<std::string_view, 2> Get() const;
3535
void Get(char* out) const;
3636
void Get(std::string* dest) const;
3737

0 commit comments

Comments
 (0)