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

Side by Side Diff: src/elements.cc

Issue 1409123003: [runtime] Avoid @@isConcatSpreadable lookup for fast path Array.prototype.concat (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: merging with master Created 4 years, 8 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
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 #include "src/elements.h" 5 #include "src/elements.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/conversions.h" 8 #include "src/conversions.h"
9 #include "src/factory.h" 9 #include "src/factory.h"
10 #include "src/isolate-inl.h" 10 #include "src/isolate-inl.h"
(...skipping 2949 matching lines...) Expand 10 before | Expand all | Expand 10 after
2960 2960
2961 2961
2962 void ElementsAccessor::TearDown() { 2962 void ElementsAccessor::TearDown() {
2963 if (elements_accessors_ == NULL) return; 2963 if (elements_accessors_ == NULL) return;
2964 #define ACCESSOR_DELETE(Class, Kind, Store) delete elements_accessors_[Kind]; 2964 #define ACCESSOR_DELETE(Class, Kind, Store) delete elements_accessors_[Kind];
2965 ELEMENTS_LIST(ACCESSOR_DELETE) 2965 ELEMENTS_LIST(ACCESSOR_DELETE)
2966 #undef ACCESSOR_DELETE 2966 #undef ACCESSOR_DELETE
2967 elements_accessors_ = NULL; 2967 elements_accessors_ = NULL;
2968 } 2968 }
2969 2969
2970
2971 Handle<JSArray> ElementsAccessor::Concat(Isolate* isolate, Arguments* args, 2970 Handle<JSArray> ElementsAccessor::Concat(Isolate* isolate, Arguments* args,
2972 uint32_t concat_size) { 2971 uint32_t concat_size,
2973 uint32_t result_len = 0; 2972 uint32_t result_len) {
2973 ElementsKind result_elements_kind = GetInitialFastElementsKind();
2974 bool has_raw_doubles = false; 2974 bool has_raw_doubles = false;
2975 ElementsKind result_elements_kind = GetInitialFastElementsKind();
2976 { 2975 {
2977 DisallowHeapAllocation no_gc; 2976 DisallowHeapAllocation no_gc;
2978 bool is_holey = false; 2977 bool is_holey = false;
2979 // Iterate through all the arguments performing checks
2980 // and calculating total length.
2981 for (uint32_t i = 0; i < concat_size; i++) { 2978 for (uint32_t i = 0; i < concat_size; i++) {
2982 JSArray* array = JSArray::cast((*args)[i]); 2979 Object* arg = (*args)[i];
2983 uint32_t len = 0; 2980 ElementsKind arg_kind = JSArray::cast(arg)->map()->elements_kind();
Toon Verwaest 2016/03/31 08:09:46 JSArray::cast(arg)->GetElementsKind()
2984 array->length()->ToArrayLength(&len);
2985
2986 // We shouldn't overflow when adding another len.
2987 const int kHalfOfMaxInt = 1 << (kBitsPerInt - 2);
2988 STATIC_ASSERT(FixedArray::kMaxLength < kHalfOfMaxInt);
2989 USE(kHalfOfMaxInt);
2990 result_len += len;
2991 DCHECK(0 <= result_len);
2992 DCHECK(result_len <= FixedDoubleArray::kMaxLength);
2993
2994 ElementsKind arg_kind = array->GetElementsKind();
2995 has_raw_doubles = has_raw_doubles || IsFastDoubleElementsKind(arg_kind); 2981 has_raw_doubles = has_raw_doubles || IsFastDoubleElementsKind(arg_kind);
2996 is_holey = is_holey || IsFastHoleyElementsKind(arg_kind); 2982 is_holey = is_holey || IsFastHoleyElementsKind(arg_kind);
2997 result_elements_kind = 2983 result_elements_kind =
2998 GetMoreGeneralElementsKind(result_elements_kind, arg_kind); 2984 GetMoreGeneralElementsKind(result_elements_kind, arg_kind);
2999 } 2985 }
3000 if (is_holey) { 2986 if (is_holey) {
3001 result_elements_kind = GetHoleyElementsKind(result_elements_kind); 2987 result_elements_kind = GetHoleyElementsKind(result_elements_kind);
3002 } 2988 }
3003 } 2989 }
3004 2990
(...skipping 17 matching lines...) Expand all
3022 // performance degradation. 3008 // performance degradation.
3023 JSArray* array = JSArray::cast((*args)[i]); 3009 JSArray* array = JSArray::cast((*args)[i]);
3024 uint32_t len = 0; 3010 uint32_t len = 0;
3025 array->length()->ToArrayLength(&len); 3011 array->length()->ToArrayLength(&len);
3026 if (len == 0) continue; 3012 if (len == 0) continue;
3027 ElementsKind from_kind = array->GetElementsKind(); 3013 ElementsKind from_kind = array->GetElementsKind();
3028 accessor->CopyElements(array, 0, from_kind, storage, insertion_index, len); 3014 accessor->CopyElements(array, 0, from_kind, storage, insertion_index, len);
3029 insertion_index += len; 3015 insertion_index += len;
3030 } 3016 }
3031 3017
3032 DCHECK_EQ(insertion_index, result_len); 3018 DCHECK(insertion_index == result_len);
Toon Verwaest 2016/03/31 08:09:46 Spurious change
3033 return result_array; 3019 return result_array;
3034 } 3020 }
3035 3021
3036 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL; 3022 ElementsAccessor** ElementsAccessor::elements_accessors_ = NULL;
3037 } // namespace internal 3023 } // namespace internal
3038 } // namespace v8 3024 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698