OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 // use the same implementation as the inlined version. | 65 // use the same implementation as the inlined version. |
66 template<typename T, class P> | 66 template<typename T, class P> |
67 void List<T, P>::ResizeAdd(const T& element) { | 67 void List<T, P>::ResizeAdd(const T& element) { |
68 ResizeAddInternal(element); | 68 ResizeAddInternal(element); |
69 } | 69 } |
70 | 70 |
71 | 71 |
72 template<typename T, class P> | 72 template<typename T, class P> |
73 void List<T, P>::ResizeAddInternal(const T& element) { | 73 void List<T, P>::ResizeAddInternal(const T& element) { |
74 ASSERT(length_ >= capacity_); | 74 ASSERT(length_ >= capacity_); |
75 // Grow the list capacity by 50%, but make sure to let it grow | 75 // Grow the list capacity by 100%, but make sure to let it grow |
76 // even when the capacity is zero (possible initial case). | 76 // even when the capacity is zero (possible initial case). |
77 int new_capacity = 1 + capacity_ + (capacity_ >> 1); | 77 int new_capacity = 1 + 2 * capacity_; |
78 // Since the element reference could be an element of the list, copy | 78 // Since the element reference could be an element of the list, copy |
79 // it out of the old backing storage before resizing. | 79 // it out of the old backing storage before resizing. |
80 T temp = element; | 80 T temp = element; |
81 Resize(new_capacity); | 81 Resize(new_capacity); |
82 data_[length_++] = temp; | 82 data_[length_++] = temp; |
83 } | 83 } |
84 | 84 |
85 | 85 |
86 template<typename T, class P> | 86 template<typename T, class P> |
87 void List<T, P>::Resize(int new_capacity) { | 87 void List<T, P>::Resize(int new_capacity) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 | 233 |
234 template <typename T> | 234 template <typename T> |
235 int SortedListBSearch(const List<T>& list, T elem) { | 235 int SortedListBSearch(const List<T>& list, T elem) { |
236 return SortedListBSearch<T>(list, elem, PointerValueCompare<T>); | 236 return SortedListBSearch<T>(list, elem, PointerValueCompare<T>); |
237 } | 237 } |
238 | 238 |
239 | 239 |
240 } } // namespace v8::internal | 240 } } // namespace v8::internal |
241 | 241 |
242 #endif // V8_LIST_INL_H_ | 242 #endif // V8_LIST_INL_H_ |
OLD | NEW |