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

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

Issue 1194943004: Get rid of JSArray::Expand and friends (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Review notes: 5 // Review notes:
6 // 6 //
7 // - The use of macros in these inline functions may seem superfluous 7 // - The use of macros in these inline functions may seem superfluous
8 // but it is absolutely needed to make sure gcc generates optimal 8 // but it is absolutely needed to make sure gcc generates optimal
9 // code. gcc is not happy when attempting to inline too deep. 9 // code. gcc is not happy when attempting to inline too deep.
10 // 10 //
(...skipping 6927 matching lines...) Expand 10 before | Expand all | Expand 10 after
6938 6938
6939 6939
6940 int Map::SlackForArraySize(int old_size, int size_limit) { 6940 int Map::SlackForArraySize(int old_size, int size_limit) {
6941 const int max_slack = size_limit - old_size; 6941 const int max_slack = size_limit - old_size;
6942 CHECK(max_slack >= 0); 6942 CHECK(max_slack >= 0);
6943 if (old_size < 4) return Min(max_slack, 1); 6943 if (old_size < 4) return Min(max_slack, 1);
6944 return Min(max_slack, old_size / 2); 6944 return Min(max_slack, old_size / 2);
6945 } 6945 }
6946 6946
6947 6947
6948 void JSArray::EnsureSize(Handle<JSArray> array, int required_size) {
6949 DCHECK(array->HasFastSmiOrObjectElements());
6950 Handle<FixedArray> elts = handle(FixedArray::cast(array->elements()));
6951 const int kArraySizeThatFitsComfortablyInNewSpace = 128;
6952 if (elts->length() < required_size) {
6953 // Doubling in size would be overkill, but leave some slack to avoid
6954 // constantly growing.
6955 Expand(array, required_size + (required_size >> 3));
6956 // It's a performance benefit to keep a frequently used array in new-space.
6957 } else if (!array->GetHeap()->new_space()->Contains(*elts) &&
6958 required_size < kArraySizeThatFitsComfortablyInNewSpace) {
6959 // Expand will allocate a new backing store in new space even if the size
6960 // we asked for isn't larger than what we had before.
6961 Expand(array, required_size);
6962 }
6963 }
6964
6965
6966 void JSArray::set_length(Smi* length) { 6948 void JSArray::set_length(Smi* length) {
6967 // Don't need a write barrier for a Smi. 6949 // Don't need a write barrier for a Smi.
6968 set_length(static_cast<Object*>(length), SKIP_WRITE_BARRIER); 6950 set_length(static_cast<Object*>(length), SKIP_WRITE_BARRIER);
6969 } 6951 }
6970 6952
6971 6953
6972 bool JSArray::SetLengthWouldNormalize(Heap* heap, uint32_t new_length) { 6954 bool JSArray::SetLengthWouldNormalize(Heap* heap, uint32_t new_length) {
6973 // If the new array won't fit in a some non-trivial fraction of the max old 6955 // If the new array won't fit in a some non-trivial fraction of the max old
6974 // space size, then force it to go dictionary mode. 6956 // space size, then force it to go dictionary mode.
6975 uint32_t max_fast_array_size = 6957 uint32_t max_fast_array_size =
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
7321 #undef READ_SHORT_FIELD 7303 #undef READ_SHORT_FIELD
7322 #undef WRITE_SHORT_FIELD 7304 #undef WRITE_SHORT_FIELD
7323 #undef READ_BYTE_FIELD 7305 #undef READ_BYTE_FIELD
7324 #undef WRITE_BYTE_FIELD 7306 #undef WRITE_BYTE_FIELD
7325 #undef NOBARRIER_READ_BYTE_FIELD 7307 #undef NOBARRIER_READ_BYTE_FIELD
7326 #undef NOBARRIER_WRITE_BYTE_FIELD 7308 #undef NOBARRIER_WRITE_BYTE_FIELD
7327 7309
7328 } } // namespace v8::internal 7310 } } // namespace v8::internal
7329 7311
7330 #endif // V8_OBJECTS_INL_H_ 7312 #endif // V8_OBJECTS_INL_H_
OLDNEW
« no previous file with comments | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698