OLD | NEW |
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 4448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4459 | 4459 |
4460 void CodeCacheHashTable::RemoveByIndex(int index) { | 4460 void CodeCacheHashTable::RemoveByIndex(int index) { |
4461 ASSERT(index >= 0); | 4461 ASSERT(index >= 0); |
4462 Heap* heap = GetHeap(); | 4462 Heap* heap = GetHeap(); |
4463 set(EntryToIndex(index), heap->null_value()); | 4463 set(EntryToIndex(index), heap->null_value()); |
4464 set(EntryToIndex(index) + 1, heap->null_value()); | 4464 set(EntryToIndex(index) + 1, heap->null_value()); |
4465 ElementRemoved(); | 4465 ElementRemoved(); |
4466 } | 4466 } |
4467 | 4467 |
4468 | 4468 |
4469 static bool HasKey(FixedArray* array, Object* key) { | |
4470 int len0 = array->length(); | |
4471 for (int i = 0; i < len0; i++) { | |
4472 Object* element = array->get(i); | |
4473 if (element->IsSmi() && key->IsSmi() && (element == key)) return true; | |
4474 if (element->IsString() && | |
4475 key->IsString() && String::cast(element)->Equals(String::cast(key))) { | |
4476 return true; | |
4477 } | |
4478 } | |
4479 return false; | |
4480 } | |
4481 | |
4482 | |
4483 MaybeObject* PolymorphicCodeCache::Update(MapList* maps, | 4469 MaybeObject* PolymorphicCodeCache::Update(MapList* maps, |
4484 Code::Flags flags, | 4470 Code::Flags flags, |
4485 Code* code) { | 4471 Code* code) { |
4486 // Initialize cache if necessary. | 4472 // Initialize cache if necessary. |
4487 if (cache()->IsUndefined()) { | 4473 if (cache()->IsUndefined()) { |
4488 Object* result; | 4474 Object* result; |
4489 { MaybeObject* maybe_result = | 4475 { MaybeObject* maybe_result = |
4490 PolymorphicCodeCacheHashTable::Allocate( | 4476 PolymorphicCodeCacheHashTable::Allocate( |
4491 PolymorphicCodeCacheHashTable::kInitialSize); | 4477 PolymorphicCodeCacheHashTable::kInitialSize); |
4492 if (!maybe_result->ToObject(&result)) return maybe_result; | 4478 if (!maybe_result->ToObject(&result)) return maybe_result; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4650 Object* current = result->get(i); | 4636 Object* current = result->get(i); |
4651 ASSERT(current->IsNumber() || current->IsString()); | 4637 ASSERT(current->IsNumber() || current->IsString()); |
4652 } | 4638 } |
4653 } | 4639 } |
4654 #endif | 4640 #endif |
4655 return result; | 4641 return result; |
4656 } | 4642 } |
4657 | 4643 |
4658 | 4644 |
4659 MaybeObject* FixedArray::UnionOfKeys(FixedArray* other) { | 4645 MaybeObject* FixedArray::UnionOfKeys(FixedArray* other) { |
4660 int len0 = length(); | 4646 ElementsAccessor* accessor = ElementsAccessor::ForArray(other); |
| 4647 MaybeObject* maybe_result = |
| 4648 accessor->AddElementsToFixedArray(other, this); |
| 4649 FixedArray* result; |
| 4650 if (!maybe_result->To<FixedArray>(&result)) return maybe_result; |
4661 #ifdef DEBUG | 4651 #ifdef DEBUG |
4662 if (FLAG_enable_slow_asserts) { | 4652 if (FLAG_enable_slow_asserts) { |
4663 for (int i = 0; i < len0; i++) { | 4653 for (int i = 0; i < result->length(); i++) { |
4664 ASSERT(get(i)->IsString() || get(i)->IsNumber()); | 4654 Object* current = result->get(i); |
| 4655 ASSERT(current->IsNumber() || current->IsString()); |
4665 } | 4656 } |
4666 } | 4657 } |
4667 #endif | 4658 #endif |
4668 int len1 = other->length(); | |
4669 // Optimize if 'other' is empty. | |
4670 // We cannot optimize if 'this' is empty, as other may have holes | |
4671 // or non keys. | |
4672 if (len1 == 0) return this; | |
4673 | |
4674 // Compute how many elements are not in this. | |
4675 int extra = 0; | |
4676 for (int y = 0; y < len1; y++) { | |
4677 Object* value = other->get(y); | |
4678 if (!value->IsTheHole() && !HasKey(this, value)) extra++; | |
4679 } | |
4680 | |
4681 if (extra == 0) return this; | |
4682 | |
4683 // Allocate the result | |
4684 Object* obj; | |
4685 { MaybeObject* maybe_obj = GetHeap()->AllocateFixedArray(len0 + extra); | |
4686 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | |
4687 } | |
4688 // Fill in the content | |
4689 AssertNoAllocation no_gc; | |
4690 FixedArray* result = FixedArray::cast(obj); | |
4691 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); | |
4692 for (int i = 0; i < len0; i++) { | |
4693 Object* e = get(i); | |
4694 ASSERT(e->IsString() || e->IsNumber()); | |
4695 result->set(i, e, mode); | |
4696 } | |
4697 // Fill in the extra keys. | |
4698 int index = 0; | |
4699 for (int y = 0; y < len1; y++) { | |
4700 Object* value = other->get(y); | |
4701 if (!value->IsTheHole() && !HasKey(this, value)) { | |
4702 Object* e = other->get(y); | |
4703 ASSERT(e->IsString() || e->IsNumber()); | |
4704 result->set(len0 + index, e, mode); | |
4705 index++; | |
4706 } | |
4707 } | |
4708 ASSERT(extra == index); | |
4709 return result; | 4659 return result; |
4710 } | 4660 } |
4711 | 4661 |
4712 | 4662 |
4713 MaybeObject* FixedArray::CopySize(int new_length) { | 4663 MaybeObject* FixedArray::CopySize(int new_length) { |
4714 Heap* heap = GetHeap(); | 4664 Heap* heap = GetHeap(); |
4715 if (new_length == 0) return heap->empty_fixed_array(); | 4665 if (new_length == 0) return heap->empty_fixed_array(); |
4716 Object* obj; | 4666 Object* obj; |
4717 { MaybeObject* maybe_obj = heap->AllocateFixedArray(new_length); | 4667 { MaybeObject* maybe_obj = heap->AllocateFixedArray(new_length); |
4718 if (!maybe_obj->ToObject(&obj)) return maybe_obj; | 4668 if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
(...skipping 6882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11601 if (break_point_objects()->IsUndefined()) return 0; | 11551 if (break_point_objects()->IsUndefined()) return 0; |
11602 // Single break point. | 11552 // Single break point. |
11603 if (!break_point_objects()->IsFixedArray()) return 1; | 11553 if (!break_point_objects()->IsFixedArray()) return 1; |
11604 // Multiple break points. | 11554 // Multiple break points. |
11605 return FixedArray::cast(break_point_objects())->length(); | 11555 return FixedArray::cast(break_point_objects())->length(); |
11606 } | 11556 } |
11607 #endif | 11557 #endif |
11608 | 11558 |
11609 | 11559 |
11610 } } // namespace v8::internal | 11560 } } // namespace v8::internal |
OLD | NEW |