move operators works

This commit is contained in:
2020-07-30 20:30:24 +03:00
parent 557f2a4d0d
commit 52062e6ccd
3 changed files with 17 additions and 21 deletions

View File

@@ -278,7 +278,7 @@ public:
memmove((void*)(&(pid_data[pid_start])), (const void*)(&(pid_data[pid_start + 1])), index * sizeof(T));
}
PIINTROSPECTION_CONTAINER_USED(T, 1)
elementNew(pid_data + pid_start + index, v);
elementNew(pid_data + pid_start + index, std::move(v));
return *this;
}
inline PIDeque<T> & insert(size_t index, const PIDeque<T> & other) {
@@ -370,11 +370,11 @@ public:
inline PIDeque<T> & push_back(T && v) {
alloc(pid_size + 1, true);
PIINTROSPECTION_CONTAINER_USED(T, 1);
elementNew(pid_data + pid_start + pid_size - 1, v);
elementNew(pid_data + pid_start + pid_size - 1, std::move(v));
return *this;
}
inline PIDeque<T> & append(const T & v) {return push_back(v);}
inline PIDeque<T> & append(T && v) {return push_back(v);}
inline PIDeque<T> & append(T && v) {return push_back(std::move(v));}
inline PIDeque<T> & append(const PIDeque<T> & t) {
assert(&t != this);
size_t ps = pid_size;
@@ -383,7 +383,7 @@ public:
return *this;
}
inline PIDeque<T> & operator <<(const T & v) {return push_back(v);}
inline PIDeque<T> & operator <<(T && v) {return push_back(v);}
inline PIDeque<T> & operator <<(T && v) {return push_back(std::move(v));}
inline PIDeque<T> & operator <<(const PIDeque<T> & t) {return append(t);}
inline PIDeque<T> & push_front(const T & v) {insert(0, v); return *this;}
@@ -451,7 +451,7 @@ private:
}
}
inline void elementNew(T * to, const T & from) {new(to)T(from);}
inline void elementNew(T * to, T && from) {piSwap(*to, from);}
inline void elementNew(T * to, T && from) {new(to)T(std::move(from));}
inline void elementDelete(T & from) {from.~T();}
inline void dealloc() {
if ((uchar*)pid_data != 0) free((uchar*)pid_data);

View File

@@ -268,7 +268,7 @@ public:
memmove((void*)(&(piv_data[index + 1])), (const void*)(&(piv_data[index])), os * sizeof(T));
}
PIINTROSPECTION_CONTAINER_USED(T, 1)
elementNew(piv_data + index, v);
elementNew(piv_data + index, std::move(v));
return *this;
}
inline PIVector<T> & insert(size_t index, const PIVector<T> & other) {
@@ -346,11 +346,11 @@ public:
inline PIVector<T> & push_back(T && v) {
alloc(piv_size + 1);
PIINTROSPECTION_CONTAINER_USED(T, 1);
elementNew(piv_data + piv_size - 1, v);
elementNew(piv_data + piv_size - 1, std::move(v));
return *this;
}
inline PIVector<T> & append(const T & v) {return push_back(v);}
inline PIVector<T> & append(T && v) {return push_back(v);}
inline PIVector<T> & append(T && v) {return push_back(std::move(v));}
inline PIVector<T> & append(const PIVector<T> & other) {
assert(&other != this);
size_t ps = piv_size;
@@ -359,7 +359,7 @@ public:
return *this;
}
inline PIVector<T> & operator <<(const T & v) {return push_back(v);}
inline PIVector<T> & operator <<(T && v) {return push_back(v);}
inline PIVector<T> & operator <<(T && v) {return push_back(std::move(v));}
inline PIVector<T> & operator <<(const PIVector<T> & other) {return append(other);}
inline PIVector<T> & push_front(const T & v) {insert(0, v); return *this;}
@@ -436,7 +436,7 @@ private:
}
}
inline void elementNew(T * to, const T & from) {new(to)T(from);}
inline void elementNew(T * to, T && from) {piSwap(*to, from);}
inline void elementNew(T * to, T && from) {new(to)T(std::move(from));}
inline void elementDelete(T & from) {from.~T();}
inline void dealloc() {
if ((uchar*)piv_data != 0) free((uchar*)piv_data);

View File

@@ -34,22 +34,18 @@ int main() {
#include "picodeparser.h"
int main() {
//piDebug = false;
piDebug = false;
double min = -1, max = -1, mean = 0;
for (int i = 0; i < 1; ++i) {
for (int i = 0; i < 50; ++i) {
PITimeMeasurer tm;
/*PICodeParser cp;
cp.parseFile("SH_plugin_base.h");*/
PIStringList sl;
sl.reserve(10);
for (int i = 0; i < 10; ++i) {
//PIString s = PIString("1234567890-=").repeated(100);
//sl.push_back(PIString("1234567890-=").repeated(100));
sl << PIString("abc").repeated(i + 1);
}
for (PIString & s : sl) {
s = s.toUpperCase();
piCout << s;
sl.reserve(50000);
for (int i = 0; i < 50000; ++i) {
// PIString s("1234567890-=");
sl.push_back(PIString("1234567890-="));
//sl << PIString("1234567890-=");
}
double ms = tm.elapsed_m();
if (min < 0) min = ms;