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 16 matching lines...) Expand all Loading... |
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 List<T, P>::List(const List<T, P>& other) { |
| 38 ASSERT(other.capacity() >= 0); |
| 39 capacity_ = other.capacity(); |
| 40 length_ = other.length(); |
| 41 if (capacity_ > 0) { |
| 42 data_ = NewData(capacity_); |
| 43 int copy_size = length_ * sizeof(T); |
| 44 const int kMinMemCpySize = 64; |
| 45 if (copy_size < kMinMemCpySize) { |
| 46 for (int i = 0; i < length_; i++) data_[i] = other.data_[i]; |
| 47 } else { |
| 48 memcpy(data_, other.data_, copy_size); |
| 49 } |
| 50 } else { |
| 51 data_ = NULL; |
| 52 } |
| 53 } |
| 54 |
| 55 |
| 56 template<typename T, class P> |
37 void List<T, P>::Add(const T& element) { | 57 void List<T, P>::Add(const T& element) { |
38 if (length_ < capacity_) { | 58 if (length_ < capacity_) { |
39 data_[length_++] = element; | 59 data_[length_++] = element; |
40 } else { | 60 } else { |
41 List<T, P>::ResizeAdd(element); | 61 List<T, P>::ResizeAdd(element); |
42 } | 62 } |
43 } | 63 } |
44 | 64 |
45 | 65 |
46 // Use two layers of inlining so that the non-inlined function can | 66 // Use two layers of inlining so that the non-inlined function can |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 ASSERT(capacity >= 0); | 158 ASSERT(capacity >= 0); |
139 data_ = (capacity > 0) ? NewData(capacity) : NULL; | 159 data_ = (capacity > 0) ? NewData(capacity) : NULL; |
140 capacity_ = capacity; | 160 capacity_ = capacity; |
141 length_ = 0; | 161 length_ = 0; |
142 } | 162 } |
143 | 163 |
144 | 164 |
145 } } // namespace v8::internal | 165 } } // namespace v8::internal |
146 | 166 |
147 #endif // V8_LIST_INL_H_ | 167 #endif // V8_LIST_INL_H_ |
OLD | NEW |