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

Side by Side Diff: src/objects.cc

Issue 7529046: Refactor UnionOfKeys into ElementsAccessor (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: review feedback Created 9 years, 4 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 | « src/objects.h ('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 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 4619 matching lines...) Expand 10 before | Expand all | Expand 10 after
4630 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 4630 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
4631 } 4631 }
4632 cache->set(EntryToIndex(entry), obj); 4632 cache->set(EntryToIndex(entry), obj);
4633 cache->set(EntryToIndex(entry) + 1, code); 4633 cache->set(EntryToIndex(entry) + 1, code);
4634 cache->ElementAdded(); 4634 cache->ElementAdded();
4635 return cache; 4635 return cache;
4636 } 4636 }
4637 4637
4638 4638
4639 MaybeObject* FixedArray::AddKeysFromJSArray(JSArray* array) { 4639 MaybeObject* FixedArray::AddKeysFromJSArray(JSArray* array) {
4640 ASSERT(!array->HasExternalArrayElements()); 4640 return array->GetElementsAccessor()->AddJSArrayKeysToFixedArray(array, this);
4641 switch (array->GetElementsKind()) {
4642 case JSObject::FAST_ELEMENTS:
4643 return UnionOfKeys(FixedArray::cast(array->elements()));
4644 case JSObject::FAST_DOUBLE_ELEMENTS:
4645 return UnionOfDoubleKeys(FixedDoubleArray::cast(array->elements()));
4646 break;
4647 case JSObject::DICTIONARY_ELEMENTS: {
4648 NumberDictionary* dict = array->element_dictionary();
4649 int size = dict->NumberOfElements();
4650
4651 // Allocate a temporary fixed array.
4652 Object* object;
4653 { MaybeObject* maybe_object = GetHeap()->AllocateFixedArray(size);
4654 if (!maybe_object->ToObject(&object)) return maybe_object;
4655 }
4656 FixedArray* key_array = FixedArray::cast(object);
4657
4658 int capacity = dict->Capacity();
4659 int pos = 0;
4660 // Copy the elements from the JSArray to the temporary fixed array.
4661 for (int i = 0; i < capacity; i++) {
4662 if (dict->IsKey(dict->KeyAt(i))) {
4663 key_array->set(pos++, dict->ValueAt(i));
4664 }
4665 }
4666 // Compute the union of this and the temporary fixed array.
4667 return UnionOfKeys(key_array);
4668 }
4669 case JSObject::NON_STRICT_ARGUMENTS_ELEMENTS:
4670 UNIMPLEMENTED();
4671 break;
4672 case JSObject::EXTERNAL_BYTE_ELEMENTS:
4673 case JSObject::EXTERNAL_UNSIGNED_BYTE_ELEMENTS:
4674 case JSObject::EXTERNAL_SHORT_ELEMENTS:
4675 case JSObject::EXTERNAL_UNSIGNED_SHORT_ELEMENTS:
4676 case JSObject::EXTERNAL_INT_ELEMENTS:
4677 case JSObject::EXTERNAL_UNSIGNED_INT_ELEMENTS:
4678 case JSObject::EXTERNAL_FLOAT_ELEMENTS:
4679 case JSObject::EXTERNAL_DOUBLE_ELEMENTS:
4680 case JSObject::EXTERNAL_PIXEL_ELEMENTS:
4681 break;
4682 }
4683 UNREACHABLE();
4684 return GetHeap()->null_value(); // Failure case needs to "return" a value.
4685 } 4641 }
4686 4642
4687 4643
4688 MaybeObject* FixedArray::UnionOfKeys(FixedArray* other) { 4644 MaybeObject* FixedArray::UnionOfKeys(FixedArray* other) {
4689 int len0 = length(); 4645 int len0 = length();
4690 #ifdef DEBUG 4646 #ifdef DEBUG
4691 if (FLAG_enable_slow_asserts) { 4647 if (FLAG_enable_slow_asserts) {
4692 for (int i = 0; i < len0; i++) { 4648 for (int i = 0; i < len0; i++) {
4693 ASSERT(get(i)->IsString() || get(i)->IsNumber()); 4649 ASSERT(get(i)->IsString() || get(i)->IsNumber());
4694 } 4650 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4732 ASSERT(e->IsString() || e->IsNumber()); 4688 ASSERT(e->IsString() || e->IsNumber());
4733 result->set(len0 + index, e, mode); 4689 result->set(len0 + index, e, mode);
4734 index++; 4690 index++;
4735 } 4691 }
4736 } 4692 }
4737 ASSERT(extra == index); 4693 ASSERT(extra == index);
4738 return result; 4694 return result;
4739 } 4695 }
4740 4696
4741 4697
4742 MaybeObject* FixedArray::UnionOfDoubleKeys(FixedDoubleArray* other) {
4743 int len0 = length();
4744 #ifdef DEBUG
4745 if (FLAG_enable_slow_asserts) {
4746 for (int i = 0; i < len0; i++) {
4747 ASSERT(get(i)->IsString() || get(i)->IsNumber());
4748 }
4749 }
4750 #endif
4751 int len1 = other->length();
4752 // Optimize if 'other' is empty.
4753 // We cannot optimize if 'this' is empty, as other may have holes
4754 // or non keys.
4755 if (len1 == 0) return this;
4756
4757 // Compute how many elements are not in this.
4758 int extra = 0;
4759 Heap* heap = GetHeap();
4760 Object* obj;
4761 for (int y = 0; y < len1; y++) {
4762 if (!other->is_the_hole(y)) {
4763 MaybeObject* maybe_obj = heap->NumberFromDouble(other->get_scalar(y));
4764 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
4765 if (!HasKey(this, obj)) extra++;
4766 }
4767 }
4768
4769 if (extra == 0) return this;
4770
4771 // Allocate the result
4772 { MaybeObject* maybe_obj = GetHeap()->AllocateFixedArray(len0 + extra);
4773 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
4774 }
4775 // Fill in the content
4776 FixedArray* result = FixedArray::cast(obj);
4777 {
4778 // Limit the scope of the AssertNoAllocation
4779 AssertNoAllocation no_gc;
4780 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
4781 for (int i = 0; i < len0; i++) {
4782 Object* e = get(i);
4783 ASSERT(e->IsString() || e->IsNumber());
4784 result->set(i, e, mode);
4785 }
4786 }
4787
4788 // Fill in the extra keys.
4789 int index = 0;
4790 for (int y = 0; y < len1; y++) {
4791 if (!other->is_the_hole(y)) {
4792 MaybeObject* maybe_obj = heap->NumberFromDouble(other->get_scalar(y));
4793 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
4794 if (!HasKey(this, obj)) {
4795 result->set(len0 + index, obj);
4796 index++;
4797 }
4798 }
4799 }
4800 ASSERT(extra == index);
4801 return result;
4802 }
4803
4804
4805 MaybeObject* FixedArray::CopySize(int new_length) { 4698 MaybeObject* FixedArray::CopySize(int new_length) {
4806 Heap* heap = GetHeap(); 4699 Heap* heap = GetHeap();
4807 if (new_length == 0) return heap->empty_fixed_array(); 4700 if (new_length == 0) return heap->empty_fixed_array();
4808 Object* obj; 4701 Object* obj;
4809 { MaybeObject* maybe_obj = heap->AllocateFixedArray(new_length); 4702 { MaybeObject* maybe_obj = heap->AllocateFixedArray(new_length);
4810 if (!maybe_obj->ToObject(&obj)) return maybe_obj; 4703 if (!maybe_obj->ToObject(&obj)) return maybe_obj;
4811 } 4704 }
4812 FixedArray* result = FixedArray::cast(obj); 4705 FixedArray* result = FixedArray::cast(obj);
4813 // Copy the content 4706 // Copy the content
4814 AssertNoAllocation no_gc; 4707 AssertNoAllocation no_gc;
(...skipping 6874 matching lines...) Expand 10 before | Expand all | Expand 10 after
11689 if (break_point_objects()->IsUndefined()) return 0; 11582 if (break_point_objects()->IsUndefined()) return 0;
11690 // Single break point. 11583 // Single break point.
11691 if (!break_point_objects()->IsFixedArray()) return 1; 11584 if (!break_point_objects()->IsFixedArray()) return 1;
11692 // Multiple break points. 11585 // Multiple break points.
11693 return FixedArray::cast(break_point_objects())->length(); 11586 return FixedArray::cast(break_point_objects())->length();
11694 } 11587 }
11695 #endif 11588 #endif
11696 11589
11697 11590
11698 } } // namespace v8::internal 11591 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698