trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mas...@apache.org
Subject [trafficserver] branch master updated: Add move operator and constructor to Result and TextBuffer
Date Sat, 17 Feb 2018 00:55:00 GMT
This is an automated email from the ASF dual-hosted git repository.

maskit pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 066c835  Add move operator and constructor to Result and TextBuffer
066c835 is described below

commit 066c8354fd4be929560485cd59fb8098ce20d404
Author: Masakazu Kitajo <maskit@apache.org>
AuthorDate: Wed Feb 14 17:40:45 2018 +0900

    Add move operator and constructor to Result and TextBuffer
---
 lib/ts/Result.h     | 14 ++++++++++++++
 lib/ts/TextBuffer.h | 11 +++++++++++
 2 files changed, 25 insertions(+)

diff --git a/lib/ts/Result.h b/lib/ts/Result.h
index c336acb..444663d 100644
--- a/lib/ts/Result.h
+++ b/lib/ts/Result.h
@@ -32,7 +32,21 @@
 // the success case. Arguably it ought to just be Error(), but Diags.h
 // already owns that name.
 
+#include <utility>
 struct Result {
+  Result() {}
+
+  Result &
+  operator=(Result &&other)
+  {
+    if (this != &other) {
+      buf = std::move(other.buf);
+    }
+    return *this;
+  }
+
+  Result(Result &&other) { *this = std::move(other); }
+
   bool
   failed() const
   {
diff --git a/lib/ts/TextBuffer.h b/lib/ts/TextBuffer.h
index 127ae0a..f631580 100644
--- a/lib/ts/TextBuffer.h
+++ b/lib/ts/TextBuffer.h
@@ -33,6 +33,7 @@
  ****************************************************************************/
 
 #include "ts/ink_platform.h"
+#include "ts/ink_memory.h"
 #include "ts/ink_apidefs.h"
 
 #include <stdarg.h>
@@ -47,6 +48,16 @@ public:
       copyFrom(rhs.bufPtr(), rhs.spaceUsed());
     }
   }
+  TextBuffer &
+  operator=(TextBuffer &&other)
+  {
+    if (this != &other) {
+      ats_free(bufferStart);
+      bufferStart       = other.bufferStart;
+      other.bufferStart = nullptr;
+    }
+    return *this;
+  }
 
   TextBuffer(int size);
   ~TextBuffer();

-- 
To stop receiving notification emails like this one, please contact
maskit@apache.org.

Mime
View raw message