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

Side by Side Diff: src/elements.cc

Issue 225623004: Callers of ElementsAccessor::AddElementsToFixedArray(), ElementsAccessor::HasElement() and Elements… (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: HasElement() polishing Created 6 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 | Annotate | Revision Log
« no previous file with comments | « src/elements.h ('k') | src/handles.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 } 615 }
616 616
617 static bool HasElementImpl(Object* receiver, 617 static bool HasElementImpl(Object* receiver,
618 JSObject* holder, 618 JSObject* holder,
619 uint32_t key, 619 uint32_t key,
620 FixedArrayBase* backing_store) { 620 FixedArrayBase* backing_store) {
621 return ElementsAccessorSubclass::GetAttributesImpl( 621 return ElementsAccessorSubclass::GetAttributesImpl(
622 receiver, holder, key, backing_store) != ABSENT; 622 receiver, holder, key, backing_store) != ABSENT;
623 } 623 }
624 624
625 virtual bool HasElement(Object* receiver, 625 virtual bool HasElement(
626 JSObject* holder, 626 Handle<Object> receiver,
627 uint32_t key, 627 Handle<JSObject> holder,
628 FixedArrayBase* backing_store) V8_FINAL V8_OVERRIDE { 628 uint32_t key,
629 if (backing_store == NULL) { 629 Handle<FixedArrayBase> backing_store) V8_FINAL V8_OVERRIDE {
630 backing_store = holder->elements(); 630 // TODO(ishell): Handlify HasElementImpl().
631 }
632 return ElementsAccessorSubclass::HasElementImpl( 631 return ElementsAccessorSubclass::HasElementImpl(
633 receiver, holder, key, backing_store); 632 *receiver, *holder, key, *backing_store);
634 } 633 }
635 634
636 // TODO(ishell): Temporary wrapper until handlified. 635 // TODO(ishell): Temporary wrapper until handlified.
637 MUST_USE_RESULT virtual Handle<Object> Get( 636 MUST_USE_RESULT virtual Handle<Object> Get(
638 Handle<Object> receiver, 637 Handle<Object> receiver,
639 Handle<JSObject> holder, 638 Handle<JSObject> holder,
640 uint32_t key, 639 uint32_t key,
641 Handle<FixedArrayBase> backing_store) V8_FINAL V8_OVERRIDE { 640 Handle<FixedArrayBase> backing_store) V8_FINAL V8_OVERRIDE {
642 CALL_HEAP_FUNCTION(holder->GetIsolate(), 641 CALL_HEAP_FUNCTION(holder->GetIsolate(),
643 Get(*receiver, *holder, key, *backing_store), 642 Get(*receiver, *holder, key, *backing_store),
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 Smi::cast(JSArray::cast(from_holder)->length())->value(); 822 Smi::cast(JSArray::cast(from_holder)->length())->value();
824 if (copy_size >= 0 && packed_size > copy_size) { 823 if (copy_size >= 0 && packed_size > copy_size) {
825 packed_size = copy_size; 824 packed_size = copy_size;
826 } 825 }
827 } 826 }
828 Handle<FixedArrayBase> from(from_holder->elements()); 827 Handle<FixedArrayBase> from(from_holder->elements());
829 ElementsAccessorSubclass::CopyElementsImpl( 828 ElementsAccessorSubclass::CopyElementsImpl(
830 from, from_start, to, from_kind, to_start, packed_size, copy_size); 829 from, from_start, to, from_kind, to_start, packed_size, copy_size);
831 } 830 }
832 831
833 MUST_USE_RESULT virtual MaybeObject* AddElementsToFixedArray( 832 virtual Handle<FixedArray> AddElementsToFixedArray(
833 Handle<Object> receiver,
834 Handle<JSObject> holder,
835 Handle<FixedArray> to,
836 Handle<FixedArrayBase> from) V8_FINAL V8_OVERRIDE {
837 CALL_HEAP_FUNCTION(to->GetIsolate(),
838 AddElementsToFixedArray(
839 receiver.is_null() ? NULL : *receiver,
840 holder.is_null() ? NULL : *holder,
841 *to,
842 *from),
843 FixedArray);
844 }
845
846 static MUST_USE_RESULT MaybeObject* AddElementsToFixedArray(
834 Object* receiver, 847 Object* receiver,
835 JSObject* holder, 848 JSObject* holder,
836 FixedArray* to, 849 FixedArray* to,
837 FixedArrayBase* from) V8_FINAL V8_OVERRIDE { 850 FixedArrayBase* from) {
838 int len0 = to->length(); 851 int len0 = to->length();
839 #ifdef ENABLE_SLOW_ASSERTS 852 #ifdef ENABLE_SLOW_ASSERTS
840 if (FLAG_enable_slow_asserts) { 853 if (FLAG_enable_slow_asserts) {
841 for (int i = 0; i < len0; i++) { 854 for (int i = 0; i < len0; i++) {
842 ASSERT(!to->get(i)->IsTheHole()); 855 ASSERT(!to->get(i)->IsTheHole());
843 } 856 }
844 } 857 }
845 #endif 858 #endif
846 if (from == NULL) {
847 from = holder->elements();
848 }
849 859
850 // Optimize if 'other' is empty. 860 // Optimize if 'other' is empty.
851 // We cannot optimize if 'this' is empty, as other may have holes. 861 // We cannot optimize if 'this' is empty, as other may have holes.
852 uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(from); 862 uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(from);
853 if (len1 == 0) return to; 863 if (len1 == 0) return to;
854 864
855 // Compute how many elements are not in other. 865 // Compute how many elements are not in other.
856 uint32_t extra = 0; 866 uint32_t extra = 0;
857 for (uint32_t y = 0; y < len1; y++) { 867 for (uint32_t y = 0; y < len1; y++) {
858 uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(from, y); 868 uint32_t key = ElementsAccessorSubclass::GetKeyForIndexImpl(from, y);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 virtual uint32_t GetCapacity(FixedArrayBase* backing_store) 925 virtual uint32_t GetCapacity(FixedArrayBase* backing_store)
916 V8_FINAL V8_OVERRIDE { 926 V8_FINAL V8_OVERRIDE {
917 return ElementsAccessorSubclass::GetCapacityImpl(backing_store); 927 return ElementsAccessorSubclass::GetCapacityImpl(backing_store);
918 } 928 }
919 929
920 static uint32_t GetKeyForIndexImpl(FixedArrayBase* backing_store, 930 static uint32_t GetKeyForIndexImpl(FixedArrayBase* backing_store,
921 uint32_t index) { 931 uint32_t index) {
922 return index; 932 return index;
923 } 933 }
924 934
925 virtual uint32_t GetKeyForIndex(FixedArrayBase* backing_store, 935 virtual uint32_t GetKeyForIndex(Handle<FixedArrayBase> backing_store,
926 uint32_t index) V8_FINAL V8_OVERRIDE { 936 uint32_t index) V8_FINAL V8_OVERRIDE {
927 return ElementsAccessorSubclass::GetKeyForIndexImpl(backing_store, index); 937 return ElementsAccessorSubclass::GetKeyForIndexImpl(*backing_store, index);
928 } 938 }
929 939
930 private: 940 private:
931 DISALLOW_COPY_AND_ASSIGN(ElementsAccessorBase); 941 DISALLOW_COPY_AND_ASSIGN(ElementsAccessorBase);
932 }; 942 };
933 943
934 944
935 // Super class for all fast element arrays. 945 // Super class for all fast element arrays.
936 template<typename FastElementsAccessorSubclass, 946 template<typename FastElementsAccessorSubclass,
937 typename KindTraits, 947 typename KindTraits,
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 } 1671 }
1662 1672
1663 static bool HasElementImpl(Object* receiver, 1673 static bool HasElementImpl(Object* receiver,
1664 JSObject* holder, 1674 JSObject* holder,
1665 uint32_t key, 1675 uint32_t key,
1666 FixedArrayBase* backing_store) { 1676 FixedArrayBase* backing_store) {
1667 return SeededNumberDictionary::cast(backing_store)->FindEntry(key) != 1677 return SeededNumberDictionary::cast(backing_store)->FindEntry(key) !=
1668 SeededNumberDictionary::kNotFound; 1678 SeededNumberDictionary::kNotFound;
1669 } 1679 }
1670 1680
1681 // TODO(ishell): Handlify when all callers are handlified.
1671 static uint32_t GetKeyForIndexImpl(FixedArrayBase* store, 1682 static uint32_t GetKeyForIndexImpl(FixedArrayBase* store,
1672 uint32_t index) { 1683 uint32_t index) {
1673 SeededNumberDictionary* dict = SeededNumberDictionary::cast(store); 1684 SeededNumberDictionary* dict = SeededNumberDictionary::cast(store);
1674 Object* key = dict->KeyAt(index); 1685 Object* key = dict->KeyAt(index);
1675 return Smi::cast(key)->value(); 1686 return Smi::cast(key)->value();
1676 } 1687 }
1677 }; 1688 };
1678 1689
1679 1690
1680 class SloppyArgumentsElementsAccessor : public ElementsAccessorBase< 1691 class SloppyArgumentsElementsAccessor : public ElementsAccessorBase<
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 UNREACHABLE(); 1829 UNREACHABLE();
1819 } 1830 }
1820 1831
1821 static uint32_t GetCapacityImpl(FixedArrayBase* backing_store) { 1832 static uint32_t GetCapacityImpl(FixedArrayBase* backing_store) {
1822 FixedArray* parameter_map = FixedArray::cast(backing_store); 1833 FixedArray* parameter_map = FixedArray::cast(backing_store);
1823 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1)); 1834 FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1));
1824 return Max(static_cast<uint32_t>(parameter_map->length() - 2), 1835 return Max(static_cast<uint32_t>(parameter_map->length() - 2),
1825 ForArray(arguments)->GetCapacity(arguments)); 1836 ForArray(arguments)->GetCapacity(arguments));
1826 } 1837 }
1827 1838
1839 // TODO(ishell): Handlify when all callers are handlified.
1828 static uint32_t GetKeyForIndexImpl(FixedArrayBase* dict, 1840 static uint32_t GetKeyForIndexImpl(FixedArrayBase* dict,
1829 uint32_t index) { 1841 uint32_t index) {
1830 return index; 1842 return index;
1831 } 1843 }
1832 1844
1833 static bool HasElementImpl(Object* receiver, 1845 static bool HasElementImpl(Object* receiver,
1834 JSObject* holder, 1846 JSObject* holder,
1835 uint32_t key, 1847 uint32_t key,
1836 FixedArrayBase* parameters) { 1848 FixedArrayBase* parameters) {
1837 FixedArray* parameter_map = FixedArray::cast(parameters); 1849 FixedArray* parameter_map = FixedArray::cast(parameters);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
2053 UNREACHABLE(); 2065 UNREACHABLE();
2054 break; 2066 break;
2055 } 2067 }
2056 2068
2057 array->set_elements(*elms); 2069 array->set_elements(*elms);
2058 array->set_length(Smi::FromInt(number_of_elements)); 2070 array->set_length(Smi::FromInt(number_of_elements));
2059 return array; 2071 return array;
2060 } 2072 }
2061 2073
2062 } } // namespace v8::internal 2074 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/elements.h ('k') | src/handles.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698