Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(665)

Unified Diff: src/utils.h

Issue 113992: fix embedded vector copy constructor and assignment. (Closed)
Patch Set: Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/cctest/test-utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils.h
diff --git a/src/utils.h b/src/utils.h
index 36a929c4abf85f509ea6ed8625f2286ccb9c4edc..137e2c4f0cf20c5f33040bada8e92a4a12e99303 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -379,6 +379,9 @@ class Vector {
// Factory method for creating empty vectors.
static Vector<T> empty() { return Vector<T>(NULL, 0); }
+ protected:
+ void set_start(T* start) { start_ = start; }
+
private:
T* start_;
int length_;
@@ -406,6 +409,22 @@ template <typename T, int kSize>
class EmbeddedVector : public Vector<T> {
public:
EmbeddedVector() : Vector<T>(buffer_, kSize) { }
+
+ // When copying, make underlying Vector to reference our buffer.
+ EmbeddedVector(const EmbeddedVector& rhs)
+ : Vector<T>(rhs) {
+ memcpy(buffer_, rhs.buffer_, sizeof(T) * kSize);
+ set_start(buffer_);
+ }
+
+ EmbeddedVector& operator=(const EmbeddedVector& rhs) {
+ if (this == &rhs) return *this;
+ Vector<T>::operator=(rhs);
+ memcpy(buffer_, rhs.buffer_, sizeof(T) * kSize);
+ set_start(buffer_);
+ return *this;
+ }
+
private:
T buffer_[kSize];
};
« no previous file with comments | « no previous file | test/cctest/test-utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698