This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 36c54da03d4 fix owned slice capacity (#28002)
36c54da03d4 is described below
commit 36c54da03d4558e84c8c518fe92649d8757569c6
Author: Kaijie Chen <[email protected]>
AuthorDate: Wed Dec 6 00:26:34 2023 +0800
fix owned slice capacity (#28002)
---
be/src/util/faststring.h | 2 +-
be/src/util/slice.h | 10 +++++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/be/src/util/faststring.h b/be/src/util/faststring.h
index bd7c07e2d5b..4edcce9836d 100644
--- a/be/src/util/faststring.h
+++ b/be/src/util/faststring.h
@@ -88,7 +88,7 @@ public:
ret = reinterpret_cast<uint8_t*>(Allocator::alloc(len_));
memcpy(ret, data_, len_);
}
- OwnedSlice result(ret, len_);
+ OwnedSlice result(ret, len_, capacity_);
len_ = 0;
capacity_ = kInitialCapacity;
data_ = initial_data_;
diff --git a/be/src/util/slice.h b/be/src/util/slice.h
index afe876a10ce..80f9616f3da 100644
--- a/be/src/util/slice.h
+++ b/be/src/util/slice.h
@@ -344,19 +344,21 @@ class OwnedSlice : private Allocator<false, false, false>
{
public:
OwnedSlice() : _slice((uint8_t*)nullptr, 0) {}
- OwnedSlice(OwnedSlice&& src) : _slice(src._slice) {
+ OwnedSlice(OwnedSlice&& src) : _slice(src._slice),
_capacity(src._capacity) {
src._slice.data = nullptr;
src._slice.size = 0;
+ src._capacity = 0;
}
OwnedSlice& operator=(OwnedSlice&& src) {
if (this != &src) {
std::swap(_slice, src._slice);
+ std::swap(_capacity, src._capacity);
}
return *this;
}
- ~OwnedSlice() { Allocator::free(_slice.data, _slice.size); }
+ ~OwnedSlice() { Allocator::free(_slice.data, _capacity); }
const Slice& slice() const { return _slice; }
@@ -364,7 +366,8 @@ private:
// faststring also inherits Allocator and disables mmap.
friend class faststring;
- OwnedSlice(uint8_t* _data, size_t size) : _slice(_data, size) {}
+ OwnedSlice(uint8_t* _data, size_t size, size_t capacity)
+ : _slice(_data, size), _capacity(capacity) {}
private:
// disable copy constructor and copy assignment
@@ -372,6 +375,7 @@ private:
void operator=(const OwnedSlice&) = delete;
Slice _slice;
+ size_t _capacity = 0;
};
} // namespace doris
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]