From: Amos Jeffries Date: Sat, 14 Mar 2015 04:42:10 +0000 (-0700) Subject: C++11: wrap move semantics operators X-Git-Tag: merge-candidate-3-v1~220 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=934f8d881559016b1d4fb2da72b896f49f6acd8a;p=thirdparty%2Fsquid.git C++11: wrap move semantics operators Allowing older not-quite-C++11 compilers to build for a while longer. Move is a performance optimization. --- diff --git a/src/SBuf.h b/src/SBuf.h index 752e9a390d..6f39f4bd17 100644 --- a/src/SBuf.h +++ b/src/SBuf.h @@ -138,12 +138,14 @@ public: /// create an empty (zero-size) SBuf SBuf(); SBuf(const SBuf &S); +#if __cplusplus >= 201103L SBuf(SBuf&& S) : store_(std::move(S.store_)), off_(S.off_), len_(S.len_) { ++stats.moves; - S.store_=NULL; + S.store_=NULL; //RefCount supports NULL, and S is about to be destructed S.off_=0; - S.len_=0; //RefCount supports NULL + S.len_=0; } +#endif /** Constructor: import c-style string * @@ -180,6 +182,7 @@ public: * Current SBuf will share backing store with the assigned one. */ SBuf& operator =(const SBuf & S) {return assign(S);} +#if __cplusplus >= 201103L SBuf& operator =(SBuf &&S) { ++stats.moves; if (this != &S) { @@ -192,6 +195,7 @@ public: } return *this; } +#endif /** Import a c-string into a SBuf, copying the data. * diff --git a/src/base/RefCount.h b/src/base/RefCount.h index 18b6cfb988..ec2a98c9d7 100644 --- a/src/base/RefCount.h +++ b/src/base/RefCount.h @@ -39,9 +39,11 @@ public: reference (p); } +#if __cplusplus >= 201103L RefCount (RefCount &&p) : p_(std::move(p.p_)) { p.p_=NULL; } +#endif RefCount& operator = (const RefCount& p) { // DO NOT CHANGE THE ORDER HERE!!! @@ -52,6 +54,7 @@ public: return *this; } +#if __cplusplus >= 201103L RefCount& operator = (RefCount&& p) { if (this != &p) { dereference(p.p_); @@ -59,6 +62,7 @@ public: } return *this; } +#endif bool operator !() const { return !p_; }