| OLD | NEW |
| 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 4864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4875 } else { | 4875 } else { |
| 4876 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity); | 4876 Object* obj = Heap::AllocateFixedArrayWithHoles(capacity); |
| 4877 if (obj->IsFailure()) return obj; | 4877 if (obj->IsFailure()) return obj; |
| 4878 new_elements = FixedArray::cast(obj); | 4878 new_elements = FixedArray::cast(obj); |
| 4879 } | 4879 } |
| 4880 set_elements(new_elements); | 4880 set_elements(new_elements); |
| 4881 return this; | 4881 return this; |
| 4882 } | 4882 } |
| 4883 | 4883 |
| 4884 | 4884 |
| 4885 void JSArray::EnsureSize(int required_size) { | |
| 4886 Handle<JSArray> self(this); | |
| 4887 ASSERT(HasFastElements()); | |
| 4888 if (elements()->length() >= required_size) return; | |
| 4889 Handle<FixedArray> old_backing(elements()); | |
| 4890 int old_size = old_backing->length(); | |
| 4891 // Doubling in size would be overkill, but leave some slack to avoid | |
| 4892 // constantly growing. | |
| 4893 int new_size = required_size + (required_size >> 3); | |
| 4894 Handle<FixedArray> new_backing = Factory::NewFixedArray(new_size); | |
| 4895 // Can't use this any more now because we may have had a GC! | |
| 4896 for (int i = 0; i < old_size; i++) new_backing->set(i, old_backing->get(i)); | |
| 4897 self->SetContent(*new_backing); | |
| 4898 } | |
| 4899 | |
| 4900 | |
| 4901 // Computes the new capacity when expanding the elements of a JSObject. | 4885 // Computes the new capacity when expanding the elements of a JSObject. |
| 4902 static int NewElementsCapacity(int old_capacity) { | 4886 static int NewElementsCapacity(int old_capacity) { |
| 4903 // (old_capacity + 50%) + 16 | 4887 // (old_capacity + 50%) + 16 |
| 4904 return old_capacity + (old_capacity >> 1) + 16; | 4888 return old_capacity + (old_capacity >> 1) + 16; |
| 4905 } | 4889 } |
| 4906 | 4890 |
| 4907 | 4891 |
| 4908 static Object* ArrayLengthRangeError() { | 4892 static Object* ArrayLengthRangeError() { |
| 4909 HandleScope scope; | 4893 HandleScope scope; |
| 4910 return Top::Throw(*Factory::NewRangeError("invalid_array_length", | 4894 return Top::Throw(*Factory::NewRangeError("invalid_array_length", |
| (...skipping 2366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7277 // No break point. | 7261 // No break point. |
| 7278 if (break_point_objects()->IsUndefined()) return 0; | 7262 if (break_point_objects()->IsUndefined()) return 0; |
| 7279 // Single beak point. | 7263 // Single beak point. |
| 7280 if (!break_point_objects()->IsFixedArray()) return 1; | 7264 if (!break_point_objects()->IsFixedArray()) return 1; |
| 7281 // Multiple break points. | 7265 // Multiple break points. |
| 7282 return FixedArray::cast(break_point_objects())->length(); | 7266 return FixedArray::cast(break_point_objects())->length(); |
| 7283 } | 7267 } |
| 7284 | 7268 |
| 7285 | 7269 |
| 7286 } } // namespace v8::internal | 7270 } } // namespace v8::internal |
| OLD | NEW |