| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 996 // Check whether the backing store should be shrunk. | 996 // Check whether the backing store should be shrunk. |
| 997 if (length <= old_capacity) { | 997 if (length <= old_capacity) { |
| 998 if (array->HasFastSmiOrObjectElements()) { | 998 if (array->HasFastSmiOrObjectElements()) { |
| 999 backing_store = JSObject::EnsureWritableFastElements(array); | 999 backing_store = JSObject::EnsureWritableFastElements(array); |
| 1000 } | 1000 } |
| 1001 if (2 * length <= old_capacity) { | 1001 if (2 * length <= old_capacity) { |
| 1002 // If more than half the elements won't be used, trim the array. | 1002 // If more than half the elements won't be used, trim the array. |
| 1003 if (length == 0) { | 1003 if (length == 0) { |
| 1004 array->initialize_elements(); | 1004 array->initialize_elements(); |
| 1005 } else { | 1005 } else { |
| 1006 backing_store->set_length(length); | 1006 int filler_size = (old_capacity - length) * ElementSize; |
| 1007 Address filler_start = backing_store->address() + | 1007 Address filler_start = backing_store->address() + |
| 1008 BackingStore::OffsetOfElementAt(length); | 1008 BackingStore::OffsetOfElementAt(length); |
| 1009 int filler_size = (old_capacity - length) * ElementSize; | |
| 1010 array->GetHeap()->CreateFillerObjectAt(filler_start, filler_size); | 1009 array->GetHeap()->CreateFillerObjectAt(filler_start, filler_size); |
| 1010 backing_store->synchronized_set_length(length); |
| 1011 } | 1011 } |
| 1012 } else { | 1012 } else { |
| 1013 // Otherwise, fill the unused tail with holes. | 1013 // Otherwise, fill the unused tail with holes. |
| 1014 int old_length = FastD2IChecked(array->length()->Number()); | 1014 int old_length = FastD2IChecked(array->length()->Number()); |
| 1015 for (int i = length; i < old_length; i++) { | 1015 for (int i = length; i < old_length; i++) { |
| 1016 Handle<BackingStore>::cast(backing_store)->set_the_hole(i); | 1016 Handle<BackingStore>::cast(backing_store)->set_the_hole(i); |
| 1017 } | 1017 } |
| 1018 } | 1018 } |
| 1019 return length_object; | 1019 return length_object; |
| 1020 } | 1020 } |
| (...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2078 UNREACHABLE(); | 2078 UNREACHABLE(); |
| 2079 break; | 2079 break; |
| 2080 } | 2080 } |
| 2081 | 2081 |
| 2082 array->set_elements(*elms); | 2082 array->set_elements(*elms); |
| 2083 array->set_length(Smi::FromInt(number_of_elements)); | 2083 array->set_length(Smi::FromInt(number_of_elements)); |
| 2084 return array; | 2084 return array; |
| 2085 } | 2085 } |
| 2086 | 2086 |
| 2087 } } // namespace v8::internal | 2087 } } // namespace v8::internal |
| OLD | NEW |