Chromium Code Reviews| Index: remoting/base/typed_buffer.h |
| diff --git a/remoting/base/typed_buffer.h b/remoting/base/typed_buffer.h |
| index c80f7200fc3b7ff8a3d7e2df0e84b3e3f0ef40b5..d0d6b2a2a90e42e1b2506d656632259936585748 100644 |
| --- a/remoting/base/typed_buffer.h |
| +++ b/remoting/base/typed_buffer.h |
| @@ -10,6 +10,7 @@ |
| #include <algorithm> |
| #include "base/basictypes.h" |
| +#include "base/logging.h" |
| #include "base/move.h" |
| namespace remoting { |
| @@ -20,11 +21,10 @@ namespace remoting { |
| // move-only semantics and typed buffer getters. |
| template <typename T> |
| class TypedBuffer { |
| - MOVE_ONLY_TYPE_FOR_CPP_03(TypedBuffer, RValue) |
| + MOVE_ONLY_TYPE_FOR_CPP_03(TypedBuffer) |
| public: |
| - TypedBuffer() : buffer_(NULL), length_(0) { |
| - } |
| + TypedBuffer() : TypedBuffer(0) {} |
| // Creates an instance of the object allocating a buffer of the given size. |
| explicit TypedBuffer(uint32 length) : buffer_(NULL), length_(length) { |
| @@ -32,12 +32,7 @@ class TypedBuffer { |
| buffer_ = reinterpret_cast<T*>(new uint8[length_]); |
| } |
| - // Move constructor for C++03 move emulation of this type. |
| - TypedBuffer(RValue rvalue) : buffer_(NULL), length_(0) { |
| - TypedBuffer temp; |
|
dcheng
2015/10/13 21:03:09
I'm not quite sure what the purpose of the temp he
dcheng
2015/10/13 21:03:39
should *not* be possible
|
| - temp.Swap(*rvalue.object); |
| - Swap(temp); |
| - } |
| + TypedBuffer(TypedBuffer&& rvalue) : TypedBuffer() { Swap(rvalue); } |
| ~TypedBuffer() { |
| if (buffer_) { |
| @@ -46,11 +41,9 @@ class TypedBuffer { |
| } |
| } |
| - // Move operator= for C++03 move emulation of this type. |
| - TypedBuffer& operator=(RValue rvalue) { |
| - TypedBuffer temp; |
|
dcheng
2015/10/13 21:03:09
I opted to just DCHECK that this is not a self-mov
|
| - temp.Swap(*rvalue.object); |
| - Swap(temp); |
| + TypedBuffer& operator=(TypedBuffer&& rvalue) { |
| + DCHECK_NE(this, &rvalue); |
|
danakj
2015/10/15 23:35:06
Swap would handle *this ok? No dcheck?
dcheng
2015/10/16 00:40:01
Done.
|
| + Swap(rvalue); |
| return *this; |
| } |