mirror of
https://github.com/google/leveldb.git
synced 2024-11-30 18:28:59 +08:00
Some cleanup of the coding library:
1) Removing the obselete api: GetLengthPrefixedSlice(const char*, const char*, Slice*) as it's not referenced anywhere. 2) A small implementation tweak of GetVarint32/GetVarint64 api:advancing the input slice past the parsed value using Slice::remove_prefix() instead of reinitializing *input_slice object. 3) coding_test.cc update. Test: make check; all tests passed.
This commit is contained in:
parent
a7bff697ba
commit
1227982913
@ -135,7 +135,7 @@ bool GetVarint32(Slice* input, uint32_t* value) {
|
||||
if (q == NULL) {
|
||||
return false;
|
||||
} else {
|
||||
*input = Slice(q, limit - q);
|
||||
input->remove_prefix(q - p);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -164,21 +164,11 @@ bool GetVarint64(Slice* input, uint64_t* value) {
|
||||
if (q == NULL) {
|
||||
return false;
|
||||
} else {
|
||||
*input = Slice(q, limit - q);
|
||||
input->remove_prefix(q - p);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const char* GetLengthPrefixedSlice(const char* p, const char* limit,
|
||||
Slice* result) {
|
||||
uint32_t len;
|
||||
p = GetVarint32Ptr(p, limit, &len);
|
||||
if (p == NULL) return NULL;
|
||||
if (p + len > limit) return NULL;
|
||||
*result = Slice(p, len);
|
||||
return p + len;
|
||||
}
|
||||
|
||||
bool GetLengthPrefixedSlice(Slice* input, Slice* result) {
|
||||
uint32_t len;
|
||||
if (GetVarint32(input, &len) &&
|
||||
|
@ -92,7 +92,7 @@ TEST(Coding, Varint32) {
|
||||
ASSERT_EQ(expected, actual);
|
||||
ASSERT_EQ(VarintLength(actual), p - start);
|
||||
}
|
||||
ASSERT_EQ(p, s.data() + s.size());
|
||||
ASSERT_EQ(p, limit);
|
||||
}
|
||||
|
||||
TEST(Coding, Varint64) {
|
||||
|
Loading…
Reference in New Issue
Block a user