Commit: bd44822f8924ca2d0bd93651fe887f84715509be
Author: Jacques Lucke
Date:   Tue Jan 22 16:44:44 2019 +0100
Branches: functions
https://developer.blender.org/rBbd44822f8924ca2d0bd93651fe887f84715509be

implement other small vector constructors

===================================================================

M       source/blender/blenlib/BLI_small_vector.hpp

===================================================================

diff --git a/source/blender/blenlib/BLI_small_vector.hpp 
b/source/blender/blenlib/BLI_small_vector.hpp
index 4cfd888b07d..f2b62c73d50 100644
--- a/source/blender/blenlib/BLI_small_vector.hpp
+++ b/source/blender/blenlib/BLI_small_vector.hpp
@@ -2,6 +2,7 @@
 
 #include "BLI_utildefines.h"
 #include <cstdlib>
+#include <cstring>
 
 namespace BLI {
 
@@ -29,6 +30,33 @@ namespace BLI {
                        }
                }
 
+               SmallVector(const SmallVector &other)
+               {
+                       if (other.is_small()) {
+                               this->m_elements = this->m_small_buffer;
+                               std::memcpy(this->m_small_buffer, 
other.m_small_buffer, sizeof(T) * other.m_size);
+                       }
+                       else {
+                               this->m_elements = (T *)std::malloc(sizeof(T) * 
other.m_capacity);
+                               std::memcpy(this->m_elements, other.m_elements, 
other.m_size);
+                       }
+                       this->m_capacity = other.m_capacity;
+                       this->m_size = other.m_size;
+               }
+
+               SmallVector(SmallVector &&other)
+               {
+                       if (other.is_small()) {
+                               this->m_elements = this->m_small_buffer;
+                               std::memcpy(this->m_small_buffer, 
other.m_small_buffer, sizeof(T) * other.m_size);
+                       }
+                       else {
+                               this->m_elements = other.m_elements;
+                       }
+                       this->m_capacity = other.m_capacity;
+                       this->m_size = other.m_size;
+               }
+
                ~SmallVector()
                {
                        if (!this->is_small()) {
@@ -36,6 +64,30 @@ namespace BLI {
                        }
                }
 
+               SmallVector &operator=(SmallVector &&other)
+               {
+                       if (this == &other) {
+                               return *this;
+                       }
+
+                       if (!this->is_small()) {
+                               std::free(this->m_elements);
+                       }
+
+                       if (other.is_small()) {
+                               this->m_elements = this->m_small_buffer;
+                               std::memcpy(this->m_small_buffer, 
other.m_small_buffer, sizeof(T) * other.m_size);
+                       }
+                       else {
+                               this->m_elements = other.m_elements;
+                       }
+
+                       this->m_capacity = other.m_capacity;
+                       this->m_size = other.m_size;
+
+                       return *this;
+               }
+
                void append(T value)
                {
                        if (this->m_size >= this->m_capacity) {

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to