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

Unified Diff: src/list-inl.h

Issue 39148: In List::Add, correctly handle the case of adding a reference to a... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 10 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') | no next file » | 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 1421)
+++ src/list-inl.h (working copy)
@@ -34,43 +34,34 @@
template<typename T, class P>
-T& List<T, P>::Add(const T& element) {
- if (length_ >= capacity_) {
+void List<T, P>::Add(const T& element) {
+ if (length_ < capacity_) {
+ data_[length_++] = element;
+ } else {
// 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);
T* new_data = NewData(new_capacity);
memcpy(new_data, data_, capacity_ * sizeof(T));
+ // Since the element reference could be an element of the list,
Kasper Lund 2009/03/05 06:21:03 It would be nice with a test of this functionality
+ // assign it to the new backing store before deleting the old.
+ new_data[length_++] = element;
DeleteData(data_);
data_ = new_data;
capacity_ = new_capacity;
}
- return data_[length_++] = element;
}
template<typename T, class P>
-Vector<T> List<T, P>::AddBlock(const T& element, int count) {
+Vector<T> List<T, P>::AddBlock(T value, int count) {
int start = length_;
- for (int i = 0; i < count; i++)
- Add(element);
+ for (int i = 0; i < count; i++) Add(value);
return Vector<T>(&data_[start], count);
}
template<typename T, class P>
-T& List<T, P>::Insert(int i, const T& element) {
- int free_index = length_ - 1;
- Add(last()); // Add grows the list if necessary.
- while (free_index > i) {
- data_[free_index] = data_[free_index - 1];
- free_index--;
- }
- data_[free_index] = element;
-}
-
-
-template<typename T, class P>
T List<T, P>::Remove(int i) {
T element = at(i);
length_--;
« no previous file with comments | « src/list.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698