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

Side by Side Diff: src/objects.cc

Issue 8122020: Fix preparation for sorting of external arrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-98773.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 10680 matching lines...) Expand 10 before | Expand all | Expand 10 after
10691 result_double->set_value(static_cast<double>(result)); 10691 result_double->set_value(static_cast<double>(result));
10692 return result_double; 10692 return result_double;
10693 } 10693 }
10694 10694
10695 10695
10696 // Collects all defined (non-hole) and non-undefined (array) elements at 10696 // Collects all defined (non-hole) and non-undefined (array) elements at
10697 // the start of the elements array. 10697 // the start of the elements array.
10698 // If the object is in dictionary mode, it is converted to fast elements 10698 // If the object is in dictionary mode, it is converted to fast elements
10699 // mode. 10699 // mode.
10700 MaybeObject* JSObject::PrepareElementsForSort(uint32_t limit) { 10700 MaybeObject* JSObject::PrepareElementsForSort(uint32_t limit) {
10701 ASSERT(!HasExternalArrayElements());
10702
10703 Heap* heap = GetHeap(); 10701 Heap* heap = GetHeap();
10704 10702
10705 if (HasDictionaryElements()) { 10703 if (HasDictionaryElements()) {
10706 // Convert to fast elements containing only the existing properties. 10704 // Convert to fast elements containing only the existing properties.
10707 // Ordering is irrelevant, since we are going to sort anyway. 10705 // Ordering is irrelevant, since we are going to sort anyway.
10708 NumberDictionary* dict = element_dictionary(); 10706 NumberDictionary* dict = element_dictionary();
10709 if (IsJSArray() || dict->requires_slow_elements() || 10707 if (IsJSArray() || dict->requires_slow_elements() ||
10710 dict->max_number_key() >= limit) { 10708 dict->max_number_key() >= limit) {
10711 return PrepareSlowElementsForSort(limit); 10709 return PrepareSlowElementsForSort(limit);
10712 } 10710 }
10713 // Convert to fast elements. 10711 // Convert to fast elements.
10714 10712
10715 Object* obj; 10713 Object* obj;
10716 { MaybeObject* maybe_obj = GetElementsTransitionMap(FAST_ELEMENTS); 10714 { MaybeObject* maybe_obj = GetElementsTransitionMap(FAST_ELEMENTS);
10717 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 10715 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
10718 } 10716 }
10719 Map* new_map = Map::cast(obj); 10717 Map* new_map = Map::cast(obj);
10720 10718
10721 PretenureFlag tenure = heap->InNewSpace(this) ? NOT_TENURED: TENURED; 10719 PretenureFlag tenure = heap->InNewSpace(this) ? NOT_TENURED: TENURED;
10722 Object* new_array; 10720 Object* new_array;
10723 { MaybeObject* maybe_new_array = 10721 { MaybeObject* maybe_new_array =
10724 heap->AllocateFixedArray(dict->NumberOfElements(), tenure); 10722 heap->AllocateFixedArray(dict->NumberOfElements(), tenure);
10725 if (!maybe_new_array->ToObject(&new_array)) return maybe_new_array; 10723 if (!maybe_new_array->ToObject(&new_array)) return maybe_new_array;
10726 } 10724 }
10727 FixedArray* fast_elements = FixedArray::cast(new_array); 10725 FixedArray* fast_elements = FixedArray::cast(new_array);
10728 dict->CopyValuesTo(fast_elements); 10726 dict->CopyValuesTo(fast_elements);
10729 10727
10730 set_map(new_map); 10728 set_map(new_map);
10731 set_elements(fast_elements); 10729 set_elements(fast_elements);
10730 } else if (HasExternalArrayElements()) {
10731 // External arrays cannot have holes or undefined elements.
10732 return Smi::FromInt(ExternalArray::cast(elements())->length());
10732 } else if (!HasFastDoubleElements()) { 10733 } else if (!HasFastDoubleElements()) {
10733 Object* obj; 10734 Object* obj;
10734 { MaybeObject* maybe_obj = EnsureWritableFastElements(); 10735 { MaybeObject* maybe_obj = EnsureWritableFastElements();
10735 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 10736 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
10736 } 10737 }
10737 } 10738 }
10738 ASSERT(HasFastTypeElements() || 10739 ASSERT(HasFastTypeElements() || HasFastDoubleElements());
10739 HasFastDoubleElements());
10740 10740
10741 // Collect holes at the end, undefined before that and the rest at the 10741 // Collect holes at the end, undefined before that and the rest at the
10742 // start, and return the number of non-hole, non-undefined values. 10742 // start, and return the number of non-hole, non-undefined values.
10743 10743
10744 FixedArrayBase* elements_base = FixedArrayBase::cast(this->elements()); 10744 FixedArrayBase* elements_base = FixedArrayBase::cast(this->elements());
10745 uint32_t elements_length = static_cast<uint32_t>(elements_base->length()); 10745 uint32_t elements_length = static_cast<uint32_t>(elements_base->length());
10746 if (limit > elements_length) { 10746 if (limit > elements_length) {
10747 limit = elements_length ; 10747 limit = elements_length ;
10748 } 10748 }
10749 if (limit == 0) { 10749 if (limit == 0) {
(...skipping 1414 matching lines...) Expand 10 before | Expand all | Expand 10 after
12164 if (break_point_objects()->IsUndefined()) return 0; 12164 if (break_point_objects()->IsUndefined()) return 0;
12165 // Single break point. 12165 // Single break point.
12166 if (!break_point_objects()->IsFixedArray()) return 1; 12166 if (!break_point_objects()->IsFixedArray()) return 1;
12167 // Multiple break points. 12167 // Multiple break points.
12168 return FixedArray::cast(break_point_objects())->length(); 12168 return FixedArray::cast(break_point_objects())->length();
12169 } 12169 }
12170 #endif 12170 #endif
12171 12171
12172 12172
12173 } } // namespace v8::internal 12173 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-98773.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698