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

Unified Diff: src/list-inl.h

Issue 115705: Remove list copy constructor (for which there was no corresponding... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
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 | « src/list.h ('k') | src/virtual-frame.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/list-inl.h
===================================================================
--- src/list-inl.h (revision 2025)
+++ src/list-inl.h (working copy)
@@ -34,32 +34,23 @@
template<typename T, class P>
-List<T, P>::List(const List<T, P>& other) {
- ASSERT(other.capacity() >= 0);
- capacity_ = other.capacity();
- length_ = other.length();
- if (capacity_ > 0) {
- data_ = NewData(capacity_);
- int copy_size = length_ * sizeof(T);
- const int kMinMemCpySize = 64;
- if (copy_size < kMinMemCpySize) {
- for (int i = 0; i < length_; i++) data_[i] = other.data_[i];
- } else {
- memcpy(data_, other.data_, copy_size);
- }
+void List<T, P>::Add(const T& element) {
+ if (length_ < capacity_) {
+ data_[length_++] = element;
} else {
- data_ = NULL;
+ List<T, P>::ResizeAdd(element);
}
}
template<typename T, class P>
-void List<T, P>::Add(const T& element) {
- if (length_ < capacity_) {
- data_[length_++] = element;
- } else {
- List<T, P>::ResizeAdd(element);
+void List<T, P>::AddAll(const List<T, P>& other) {
+ int result_length = length_ + other.length_;
+ if (capacity_ < result_length) Resize(result_length);
+ for (int i = 0; i < other.length_; i++) {
+ data_[length_ + i] = other.data_[i];
}
+ length_ = result_length;
}
@@ -77,11 +68,18 @@
// Grow the list capacity by 50%, but make sure to let it grow
// even when the capacity is zero (possible initial case).
int new_capacity = 1 + capacity_ + (capacity_ >> 1);
+ // Since the element reference could be an element of the list, copy
+ // it out of the old backing storage before resizing.
+ T temp = element;
+ Resize(new_capacity);
+ data_[length_++] = temp;
+}
+
+
+template<typename T, class P>
+void List<T, P>::Resize(int new_capacity) {
T* new_data = List<T, P>::NewData(new_capacity);
memcpy(new_data, data_, capacity_ * sizeof(T));
- // Since the element reference could be an element of the list,
- // assign it to the new backing store before deleting the old.
- new_data[length_++] = element;
List<T, P>::DeleteData(data_);
data_ = new_data;
capacity_ = new_capacity;
« no previous file with comments | « src/list.h ('k') | src/virtual-frame.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698