Fix BufferSlice size statistics.
GitOrigin-RevId: 2dcfeb4981435b93106df5817c849df8a94ba14f
This commit is contained in:
parent
8ac59dc77d
commit
4455b66e8b
@ -147,10 +147,10 @@ class BufferSlice {
|
|||||||
debug_untrack();
|
debug_untrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug_track() {
|
void debug_track() const {
|
||||||
BufferAllocator::track_buffer_slice(static_cast<int64>(size()));
|
BufferAllocator::track_buffer_slice(static_cast<int64>(size()));
|
||||||
}
|
}
|
||||||
void debug_untrack() {
|
void debug_untrack() const {
|
||||||
BufferAllocator::track_buffer_slice(-static_cast<int64>(size()));
|
BufferAllocator::track_buffer_slice(-static_cast<int64>(size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,6 +214,7 @@ class BufferSlice {
|
|||||||
|
|
||||||
BufferSlice from_slice(Slice slice) const {
|
BufferSlice from_slice(Slice slice) const {
|
||||||
auto res = BufferSlice(BufferAllocator::create_reader(buffer_));
|
auto res = BufferSlice(BufferAllocator::create_reader(buffer_));
|
||||||
|
res.debug_untrack();
|
||||||
res.begin_ = static_cast<size_t>(slice.ubegin() - buffer_->data_);
|
res.begin_ = static_cast<size_t>(slice.ubegin() - buffer_->data_);
|
||||||
res.end_ = static_cast<size_t>(slice.uend() - buffer_->data_);
|
res.end_ = static_cast<size_t>(slice.uend() - buffer_->data_);
|
||||||
res.debug_track();
|
res.debug_track();
|
||||||
|
@ -134,6 +134,16 @@ TEST(Http, reader) {
|
|||||||
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR));
|
SET_VERBOSITY_LEVEL(VERBOSITY_NAME(ERROR));
|
||||||
auto start_mem = BufferAllocator::get_buffer_mem();
|
auto start_mem = BufferAllocator::get_buffer_mem();
|
||||||
auto start_size = BufferAllocator::get_buffer_slice_size();
|
auto start_size = BufferAllocator::get_buffer_slice_size();
|
||||||
|
{
|
||||||
|
BufferSlice a("test test");
|
||||||
|
BufferSlice b = std::move(a);
|
||||||
|
a = std::move(b);
|
||||||
|
BufferSlice c = a.from_slice(a);
|
||||||
|
CHECK(c.size() == a.size());
|
||||||
|
}
|
||||||
|
clear_thread_locals();
|
||||||
|
ASSERT_EQ(start_mem, BufferAllocator::get_buffer_mem());
|
||||||
|
ASSERT_EQ(start_size, BufferAllocator::get_buffer_slice_size());
|
||||||
for (int i = 0; i < 20; i++) {
|
for (int i = 0; i < 20; i++) {
|
||||||
td::ChainBufferWriter input_writer;
|
td::ChainBufferWriter input_writer;
|
||||||
auto input = input_writer.extract_reader();
|
auto input = input_writer.extract_reader();
|
||||||
|
Loading…
Reference in New Issue
Block a user