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

Side by Side Diff: src/objects.cc

Issue 3595013: Do not shortcut union of keys if lhs is empty. (Closed)
Patch Set: Addressing Kasper's comments Created 10 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
« no previous file with comments | « src/handles.cc ('k') | test/cctest/test-api.cc » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 3583 matching lines...) Expand 10 before | Expand all | Expand 10 after
3594 default: 3594 default:
3595 UNREACHABLE(); 3595 UNREACHABLE();
3596 } 3596 }
3597 UNREACHABLE(); 3597 UNREACHABLE();
3598 return Heap::null_value(); // Failure case needs to "return" a value. 3598 return Heap::null_value(); // Failure case needs to "return" a value.
3599 } 3599 }
3600 3600
3601 3601
3602 Object* FixedArray::UnionOfKeys(FixedArray* other) { 3602 Object* FixedArray::UnionOfKeys(FixedArray* other) {
3603 int len0 = length(); 3603 int len0 = length();
3604 #ifdef DEBUG
3605 if (FLAG_enable_slow_asserts) {
3606 for (int i = 0; i < len0; i++) {
3607 ASSERT(get(i)->IsString() || get(i)->IsNumber());
3608 }
3609 }
3610 #endif
3604 int len1 = other->length(); 3611 int len1 = other->length();
3605 // Optimize if either is empty. 3612 // Optimize if 'other' is empty.
3606 if (len0 == 0) return other; 3613 // We cannot optimize if 'this' is empty, as other may have holes
3614 // or non keys.
3607 if (len1 == 0) return this; 3615 if (len1 == 0) return this;
3608 3616
3609 // Compute how many elements are not in this. 3617 // Compute how many elements are not in this.
3610 int extra = 0; 3618 int extra = 0;
3611 for (int y = 0; y < len1; y++) { 3619 for (int y = 0; y < len1; y++) {
3612 Object* value = other->get(y); 3620 Object* value = other->get(y);
3613 if (!value->IsTheHole() && !HasKey(this, value)) extra++; 3621 if (!value->IsTheHole() && !HasKey(this, value)) extra++;
3614 } 3622 }
3615 3623
3616 if (extra == 0) return this; 3624 if (extra == 0) return this;
3617 3625
3618 // Allocate the result 3626 // Allocate the result
3619 Object* obj = Heap::AllocateFixedArray(len0 + extra); 3627 Object* obj = Heap::AllocateFixedArray(len0 + extra);
3620 if (obj->IsFailure()) return obj; 3628 if (obj->IsFailure()) return obj;
3621 // Fill in the content 3629 // Fill in the content
3622 AssertNoAllocation no_gc; 3630 AssertNoAllocation no_gc;
3623 FixedArray* result = FixedArray::cast(obj); 3631 FixedArray* result = FixedArray::cast(obj);
3624 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); 3632 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc);
3625 for (int i = 0; i < len0; i++) { 3633 for (int i = 0; i < len0; i++) {
3626 result->set(i, get(i), mode); 3634 Object* e = get(i);
3635 ASSERT(e->IsString() || e->IsNumber());
3636 result->set(i, e, mode);
3627 } 3637 }
3628 // Fill in the extra keys. 3638 // Fill in the extra keys.
3629 int index = 0; 3639 int index = 0;
3630 for (int y = 0; y < len1; y++) { 3640 for (int y = 0; y < len1; y++) {
3631 Object* value = other->get(y); 3641 Object* value = other->get(y);
3632 if (!value->IsTheHole() && !HasKey(this, value)) { 3642 if (!value->IsTheHole() && !HasKey(this, value)) {
3633 result->set(len0 + index, other->get(y), mode); 3643 Object* e = other->get(y);
3644 ASSERT(e->IsString() || e->IsNumber());
3645 result->set(len0 + index, e, mode);
3634 index++; 3646 index++;
3635 } 3647 }
3636 } 3648 }
3637 ASSERT(extra == index); 3649 ASSERT(extra == index);
3638 return result; 3650 return result;
3639 } 3651 }
3640 3652
3641 3653
3642 Object* FixedArray::CopySize(int new_length) { 3654 Object* FixedArray::CopySize(int new_length) {
3643 if (new_length == 0) return Heap::empty_fixed_array(); 3655 if (new_length == 0) return Heap::empty_fixed_array();
(...skipping 5400 matching lines...) Expand 10 before | Expand all | Expand 10 after
9044 if (break_point_objects()->IsUndefined()) return 0; 9056 if (break_point_objects()->IsUndefined()) return 0;
9045 // Single beak point. 9057 // Single beak point.
9046 if (!break_point_objects()->IsFixedArray()) return 1; 9058 if (!break_point_objects()->IsFixedArray()) return 1;
9047 // Multiple break points. 9059 // Multiple break points.
9048 return FixedArray::cast(break_point_objects())->length(); 9060 return FixedArray::cast(break_point_objects())->length();
9049 } 9061 }
9050 #endif 9062 #endif
9051 9063
9052 9064
9053 } } // namespace v8::internal 9065 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/handles.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698