Skip to content

Commit ce5d166

Browse files
authored
fix(server): Move LpGetView to core target (#6076)
1 parent 81a64c3 commit ce5d166

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

src/core/detail/listpack_wrap.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
#include "core/detail/listpack_wrap.h"
55

6-
#include "server/container_utils.h"
6+
#include "base/logging.h"
77

88
extern "C" {
99
#include "redis/listpack.h"
@@ -27,10 +27,9 @@ void ListpackWrap::Iterator::Read() {
2727
if (!ptr_)
2828
return;
2929

30-
using container_utils::LpGetView;
31-
key_v_ = LpGetView(ptr_, intbuf_[0]);
30+
key_v_ = GetView(ptr_, intbuf_[0]);
3231
next_ptr_ = lpNext(lp_, ptr_);
33-
value_v_ = LpGetView(next_ptr_, intbuf_[1]);
32+
value_v_ = GetView(next_ptr_, intbuf_[1]);
3433
next_ptr_ = lpNext(lp_, next_ptr_);
3534
}
3635

@@ -115,6 +114,13 @@ ListpackWrap::Iterator ListpackWrap::end() const {
115114
return Iterator{lp_, nullptr, intbuf_};
116115
}
117116

117+
std::string_view ListpackWrap::GetView(uint8_t* lp_it, uint8_t int_buf[]) {
118+
int64_t ele_len = 0;
119+
uint8_t* elem = lpGet(lp_it, &ele_len, int_buf);
120+
DCHECK(elem);
121+
return std::string_view{reinterpret_cast<char*>(elem), size_t(ele_len)};
122+
}
123+
118124
bool ListpackWrap::Iterator::operator==(const Iterator& other) const {
119125
return lp_ == other.lp_ && ptr_ == other.ptr_;
120126
}

src/core/detail/listpack_wrap.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ struct ListpackWrap {
5757
Iterator end() const;
5858
size_t size() const; // number of entries
5959

60+
// Get view from raw listpack iterator
61+
static std::string_view GetView(uint8_t* lp_it, uint8_t int_buf[]);
62+
6063
private:
6164
uint8_t* lp_; // the listpack itself
6265
mutable IntBuf intbuf_; // buffer for integers decoded to strings

src/server/container_utils.cc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,6 @@ StringMap* GetStringMap(const PrimeValue& pv, const DbContext& db_context) {
272272
return res;
273273
}
274274

275-
string_view LpGetView(uint8_t* lp_it, uint8_t int_buf[]) {
276-
int64_t ele_len = 0;
277-
uint8_t* elem = lpGet(lp_it, &ele_len, int_buf);
278-
DCHECK(elem);
279-
return std::string_view{reinterpret_cast<char*>(elem), size_t(ele_len)};
280-
}
281-
282275
OpResult<string> RunCbOnFirstNonEmptyBlocking(Transaction* trans, int req_obj_type,
283276
BlockingResultCb func, unsigned limit_ms,
284277
bool* block_flag, bool* pause_flag) {

src/server/container_utils.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ bool IterateMap(const PrimeValue& pv, const IterateKVFunc& func);
7474
// Get StringMap pointer from primetable value. Sets expire time from db_context
7575
StringMap* GetStringMap(const PrimeValue& pv, const DbContext& db_context);
7676

77-
// Get string_view from listpack poiner. Intbuf to store integer values as strings.
78-
std::string_view LpGetView(uint8_t* lp_it, uint8_t int_buf[]);
79-
8077
using BlockingResultCb =
8178
std::function<void(Transaction*, EngineShard*, std::string_view /* key */)>;
8279

src/server/rdb_load.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ extern "C" {
2727
#include "base/flags.h"
2828
#include "base/logging.h"
2929
#include "core/bloom.h"
30+
#include "core/detail/listpack_wrap.h"
3031
#include "core/json/json_object.h"
3132
#include "core/qlist.h"
3233
#include "core/sorted_map.h"
3334
#include "core/string_map.h"
3435
#include "core/string_set.h"
3536
#include "server/cluster/cluster_config.h"
36-
#include "server/container_utils.h"
3737
#include "server/engine_shard_set.h"
3838
#include "server/error.h"
3939
#include "server/family_utils.h"
@@ -893,7 +893,7 @@ void RdbLoaderBase::OpaqueObjLoader::HandleBlob(string_view blob) {
893893
StringSet* set = CompactObj::AllocateMR<StringSet>();
894894
for (unsigned char* cur = lpFirst(lp); cur != nullptr; cur = lpNext(lp, cur)) {
895895
unsigned char field_buf[LP_INTBUF_SIZE];
896-
string_view elem = container_utils::LpGetView(cur, field_buf);
896+
string_view elem = detail::ListpackWrap::GetView(cur, field_buf);
897897
if (!set->Add(elem)) {
898898
LOG(ERROR) << "Duplicate member " << elem;
899899
ec_ = RdbError(errc::duplicate_key);

0 commit comments

Comments
 (0)