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

Side by Side Diff: src/list-inl.h

Issue 40290: Experimental: Merge 1395:1441 from bleeding_edge branch to the... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/global/
Patch Set: Created 11 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/list.h ('k') | src/log.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 16 matching lines...) Expand all
27 27
28 #ifndef V8_LIST_INL_H_ 28 #ifndef V8_LIST_INL_H_
29 #define V8_LIST_INL_H_ 29 #define V8_LIST_INL_H_
30 30
31 #include "list.h" 31 #include "list.h"
32 32
33 namespace v8 { namespace internal { 33 namespace v8 { namespace internal {
34 34
35 35
36 template<typename T, class P> 36 template<typename T, class P>
37 T& List<T, P>::Add(const T& element) { 37 void List<T, P>::Add(const T& element) {
38 if (length_ >= capacity_) { 38 if (length_ < capacity_) {
39 data_[length_++] = element;
40 } else {
39 // Grow the list capacity by 50%, but make sure to let it grow 41 // Grow the list capacity by 50%, but make sure to let it grow
40 // even when the capacity is zero (possible initial case). 42 // even when the capacity is zero (possible initial case).
41 int new_capacity = 1 + capacity_ + (capacity_ >> 1); 43 int new_capacity = 1 + capacity_ + (capacity_ >> 1);
42 T* new_data = NewData(new_capacity); 44 T* new_data = NewData(new_capacity);
43 memcpy(new_data, data_, capacity_ * sizeof(T)); 45 memcpy(new_data, data_, capacity_ * sizeof(T));
46 // Since the element reference could be an element of the list,
47 // assign it to the new backing store before deleting the old.
48 new_data[length_++] = element;
44 DeleteData(data_); 49 DeleteData(data_);
45 data_ = new_data; 50 data_ = new_data;
46 capacity_ = new_capacity; 51 capacity_ = new_capacity;
47 } 52 }
48 return data_[length_++] = element;
49 } 53 }
50 54
51 55
52 template<typename T, class P> 56 template<typename T, class P>
53 Vector<T> List<T, P>::AddBlock(const T& element, int count) { 57 Vector<T> List<T, P>::AddBlock(T value, int count) {
54 int start = length_; 58 int start = length_;
55 for (int i = 0; i < count; i++) 59 for (int i = 0; i < count; i++) Add(value);
56 Add(element);
57 return Vector<T>(&data_[start], count); 60 return Vector<T>(&data_[start], count);
58 } 61 }
59 62
60 63
61 template<typename T, class P> 64 template<typename T, class P>
62 T List<T, P>::Remove(int i) { 65 T List<T, P>::Remove(int i) {
63 T element = at(i); 66 T element = at(i);
64 length_--; 67 length_--;
65 while (i < length_) { 68 while (i < length_) {
66 data_[i] = data_[i + 1]; 69 data_[i] = data_[i + 1];
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 ASSERT(capacity >= 0); 123 ASSERT(capacity >= 0);
121 data_ = (capacity > 0) ? NewData(capacity) : NULL; 124 data_ = (capacity > 0) ? NewData(capacity) : NULL;
122 capacity_ = capacity; 125 capacity_ = capacity;
123 length_ = 0; 126 length_ = 0;
124 } 127 }
125 128
126 129
127 } } // namespace v8::internal 130 } } // namespace v8::internal
128 131
129 #endif // V8_LIST_INL_H_ 132 #endif // V8_LIST_INL_H_
OLDNEW
« no previous file with comments | « src/list.h ('k') | src/log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698