diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-07-25 22:54:14 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-07-31 17:04:17 +0200 |
commit | c43f771f6e43c73cc34010f0b105bef1907f0326 (patch) | |
tree | bd690e13ea78a8838eef2e385a2f2b48b055ab35 /vespalib/src | |
parent | 5d556da6996ba3fd81d6bfb8a48ef25428978eee (diff) |
Avoid copy by stealing allocation, and by presizing buffer.
Diffstat (limited to 'vespalib/src')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/array.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/util/array.h b/vespalib/src/vespa/vespalib/util/array.h index 3cee5726793..b766ed56844 100644 --- a/vespalib/src/vespa/vespalib/util/array.h +++ b/vespalib/src/vespa/vespalib/util/array.h @@ -145,6 +145,11 @@ public: const T & operator [] (size_t i) const { return *array(i); } bool operator == (const Array & rhs) const; bool operator != (const Array & rhs) const; + + static Alloc stealAlloc(Array && rhs) { + rhs._sz = 0; + return std::move(rhs._array); + } private: T * array(size_t i) { return static_cast<T *>(_array.get()) + i; } const T * array(size_t i) const { return static_cast<const T *>(_array.get()) + i; } |