SkDynamicMemoryWStream: make moveable
Motivation: using this in an experiment of mine (I want a std::vector<SkDynamicMemoryWStream>.) Change-Id: I28e2c468156ace2f9e7d5e09937e05bc8b7e8200 Reviewed-on: https://skia-review.googlesource.com/c/159326 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Hal Canary <halcanary@google.com>
This commit is contained in:
parent
4302eb9a6e
commit
2e01805298
@ -278,9 +278,7 @@ public:
|
||||
static int SizeOfPackedUInt(size_t value);
|
||||
|
||||
private:
|
||||
SkWStream(SkWStream&&) = delete;
|
||||
SkWStream(const SkWStream&) = delete;
|
||||
SkWStream& operator=(SkWStream&&) = delete;
|
||||
SkWStream& operator=(const SkWStream&) = delete;
|
||||
};
|
||||
|
||||
@ -459,7 +457,9 @@ private:
|
||||
|
||||
class SK_API SkDynamicMemoryWStream : public SkWStream {
|
||||
public:
|
||||
SkDynamicMemoryWStream();
|
||||
SkDynamicMemoryWStream() = default;
|
||||
SkDynamicMemoryWStream(SkDynamicMemoryWStream&&);
|
||||
SkDynamicMemoryWStream& operator=(SkDynamicMemoryWStream&&);
|
||||
~SkDynamicMemoryWStream() override;
|
||||
|
||||
bool write(const void* buffer, size_t size) override;
|
||||
@ -488,9 +488,9 @@ public:
|
||||
void padToAlign4();
|
||||
private:
|
||||
struct Block;
|
||||
Block* fHead;
|
||||
Block* fTail;
|
||||
size_t fBytesWrittenBeforeTail;
|
||||
Block* fHead = nullptr;
|
||||
Block* fTail = nullptr;
|
||||
size_t fBytesWrittenBeforeTail = 0;
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
void validate() const;
|
||||
|
@ -476,9 +476,23 @@ struct SkDynamicMemoryWStream::Block {
|
||||
}
|
||||
};
|
||||
|
||||
SkDynamicMemoryWStream::SkDynamicMemoryWStream()
|
||||
: fHead(nullptr), fTail(nullptr), fBytesWrittenBeforeTail(0)
|
||||
{}
|
||||
SkDynamicMemoryWStream::SkDynamicMemoryWStream(SkDynamicMemoryWStream&& other)
|
||||
: fHead(other.fHead)
|
||||
, fTail(other.fTail)
|
||||
, fBytesWrittenBeforeTail(other.fBytesWrittenBeforeTail)
|
||||
{
|
||||
other.fHead = nullptr;
|
||||
other.fTail = nullptr;
|
||||
other.fBytesWrittenBeforeTail = 0;
|
||||
}
|
||||
|
||||
SkDynamicMemoryWStream& SkDynamicMemoryWStream::operator=(SkDynamicMemoryWStream&& other) {
|
||||
if (this != &other) {
|
||||
this->~SkDynamicMemoryWStream();
|
||||
new (this) SkDynamicMemoryWStream(std::move(other));
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
SkDynamicMemoryWStream::~SkDynamicMemoryWStream() {
|
||||
this->reset();
|
||||
|
Loading…
Reference in New Issue
Block a user