Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion be/src/util/faststring.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class faststring : private Allocator<false, false, false> {
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_;
Expand Down
10 changes: 7 additions & 3 deletions be/src/util/slice.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,34 +344,38 @@ 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); }
Comment thread
yiguolei marked this conversation as resolved.

const Slice& slice() const { return _slice; }

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
OwnedSlice(const OwnedSlice&) = delete;
void operator=(const OwnedSlice&) = delete;

Slice _slice;
size_t _capacity = 0;
};

} // namespace doris