[Improvement](Slice) support move constructor and operator for Slice (#23694)

This commit is contained in:
HHoflittlefish777
2023-09-01 21:05:10 +08:00
committed by GitHub
parent ba863a992e
commit e0efda1234

View File

@ -80,6 +80,31 @@ public:
data(const_cast<char*>(s)),
size(strlen(s)) {}
Slice(const Slice& src) : data(src.data), size(src.size) {}
Slice& operator=(const Slice& src) {
if (this != &src) {
data = src.data;
size = src.size;
}
return *this;
}
Slice(Slice&& src) : data(src.data), size(src.size) {
src.data = nullptr;
src.size = 0;
}
Slice& operator=(Slice&& src) {
if (this != &src) {
data = src.data;
size = src.size;
src.data = nullptr;
src.size = 0;
}
return *this;
}
/// @return A pointer to the beginning of the referenced data.
const char* get_data() const { return data; }