diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-04-05 17:22:55 +0300 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-04-05 22:35:04 +0300 |
commit | 300c91b46a3b3d2bfb529c7cc6c455d685fb6b5e (patch) | |
tree | d4bcd565f06e78e77489059e53ff6b2424cf8ab6 /include | |
parent | 5a173faec1aed27e08cdded48371cf9c7752b779 (diff) | |
download | qtlocation-mapboxgl-300c91b46a3b3d2bfb529c7cc6c455d685fb6b5e.tar.gz |
[core] Move should not call destructors
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/style/conversion_impl.hpp | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/include/mbgl/style/conversion_impl.hpp b/include/mbgl/style/conversion_impl.hpp index 27b2ee1917..0551187f6a 100644 --- a/include/mbgl/style/conversion_impl.hpp +++ b/include/mbgl/style/conversion_impl.hpp @@ -89,29 +89,20 @@ public: new (static_cast<void*>(&storage)) std::decay_t<T>(std::forward<T>(value)); } - Convertible(Convertible&& v) - : vtable(v.vtable) - { - if (vtable) { - vtable->move(std::move(v.storage), this->storage); - } + Convertible(Convertible&& v) : vtable(v.vtable) { + vtable->move(std::move(v.storage), storage); } ~Convertible() { - if (vtable) { - vtable->destroy(storage); - } + vtable->destroy(storage); } Convertible& operator=(Convertible&& v) { - if (vtable) { + if (this != &v) { vtable->destroy(storage); + vtable = v.vtable; + vtable->move(std::move(v.storage), storage); } - vtable = v.vtable; - if (vtable) { - vtable->move(std::move(v.storage), this->storage); - } - v.vtable = nullptr; return *this; } @@ -235,9 +226,7 @@ private: using Traits = ConversionTraits<T>; static VTable vtable = { [] (Storage&& src, Storage& dest) { - auto srcValue = reinterpret_cast<T&&>(src); - new (static_cast<void*>(&dest)) T(std::move(srcValue)); - srcValue.~T(); + new (static_cast<void*>(&dest)) T(reinterpret_cast<T&&>(src)); }, [] (Storage& s) { reinterpret_cast<T&>(s).~T(); |