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

Side by Side Diff: src/value-serializer.cc

Issue 2342293003: Use a plain FixedArray rather than a SeededNumberDictionary for ValueDeserializer::id_map_. (Closed)
Patch Set: Created 4 years, 3 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/value-serializer.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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/value-serializer.h" 5 #include "src/value-serializer.h"
6 6
7 #include <type_traits> 7 #include <type_traits>
8 8
9 #include "src/base/logging.h" 9 #include "src/base/logging.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 } 777 }
778 778
779 ValueDeserializer::ValueDeserializer(Isolate* isolate, 779 ValueDeserializer::ValueDeserializer(Isolate* isolate,
780 Vector<const uint8_t> data, 780 Vector<const uint8_t> data,
781 v8::ValueDeserializer::Delegate* delegate) 781 v8::ValueDeserializer::Delegate* delegate)
782 : isolate_(isolate), 782 : isolate_(isolate),
783 delegate_(delegate), 783 delegate_(delegate),
784 position_(data.start()), 784 position_(data.start()),
785 end_(data.start() + data.length()), 785 end_(data.start() + data.length()),
786 pretenure_(data.length() > kPretenureThreshold ? TENURED : NOT_TENURED), 786 pretenure_(data.length() > kPretenureThreshold ? TENURED : NOT_TENURED),
787 id_map_(Handle<SeededNumberDictionary>::cast( 787 id_map_(Handle<FixedArray>::cast(isolate->global_handles()->Create(
788 isolate->global_handles()->Create( 788 isolate_->heap()->empty_fixed_array()))) {}
789 *SeededNumberDictionary::New(isolate, 0)))) {}
790 789
791 ValueDeserializer::~ValueDeserializer() { 790 ValueDeserializer::~ValueDeserializer() {
792 GlobalHandles::Destroy(Handle<Object>::cast(id_map_).location()); 791 GlobalHandles::Destroy(Handle<Object>::cast(id_map_).location());
793 792
794 Handle<Object> transfer_map_handle; 793 Handle<Object> transfer_map_handle;
795 if (array_buffer_transfer_map_.ToHandle(&transfer_map_handle)) { 794 if (array_buffer_transfer_map_.ToHandle(&transfer_map_handle)) {
796 GlobalHandles::Destroy(transfer_map_handle.location()); 795 GlobalHandles::Destroy(transfer_map_handle.location());
797 } 796 }
798 } 797 }
799 798
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 isolate_, object, key, &success, LookupIterator::OWN); 1567 isolate_, object, key, &success, LookupIterator::OWN);
1569 if (!success || 1568 if (!success ||
1570 JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, NONE) 1569 JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, NONE)
1571 .is_null()) { 1570 .is_null()) {
1572 return Nothing<uint32_t>(); 1571 return Nothing<uint32_t>();
1573 } 1572 }
1574 } 1573 }
1575 } 1574 }
1576 1575
1577 bool ValueDeserializer::HasObjectWithID(uint32_t id) { 1576 bool ValueDeserializer::HasObjectWithID(uint32_t id) {
1578 return id_map_->Has(isolate_, id); 1577 return static_cast<unsigned>(id_map_->length()) > id &&
1578 id_map_->get(id) != isolate_->heap()->the_hole_value();
Camillo Bruni 2016/09/16 20:49:37 nit: use IsTheHole(isolate_)
jbroman 2016/09/17 05:00:51 Done.
1579 } 1579 }
1580 1580
1581 MaybeHandle<JSReceiver> ValueDeserializer::GetObjectWithID(uint32_t id) { 1581 MaybeHandle<JSReceiver> ValueDeserializer::GetObjectWithID(uint32_t id) {
1582 int index = id_map_->FindEntry(isolate_, id); 1582 if (id >= static_cast<unsigned>(id_map_->length())) {
1583 if (index == SeededNumberDictionary::kNotFound) {
1584 return MaybeHandle<JSReceiver>(); 1583 return MaybeHandle<JSReceiver>();
1585 } 1584 }
1586 Object* value = id_map_->ValueAt(index); 1585 Object* value = id_map_->get(id);
1586 if (value == isolate_->heap()->the_hole_value()) {
Camillo Bruni 2016/09/16 20:49:37 nit: use IsTheHole(isolate_)
jbroman 2016/09/17 05:00:51 Done.
1587 return MaybeHandle<JSReceiver>();
1588 }
1587 DCHECK(value->IsJSReceiver()); 1589 DCHECK(value->IsJSReceiver());
1588 return Handle<JSReceiver>(JSReceiver::cast(value), isolate_); 1590 return Handle<JSReceiver>(JSReceiver::cast(value), isolate_);
1589 } 1591 }
1590 1592
1591 void ValueDeserializer::AddObjectWithID(uint32_t id, 1593 void ValueDeserializer::AddObjectWithID(uint32_t id,
1592 Handle<JSReceiver> object) { 1594 Handle<JSReceiver> object) {
1593 DCHECK(!HasObjectWithID(id)); 1595 DCHECK(!HasObjectWithID(id));
1594 const bool used_as_prototype = false; 1596 Handle<FixedArray> new_array = FixedArray::SetAndGrow(id_map_, id, object);
1595 Handle<SeededNumberDictionary> new_dictionary =
1596 SeededNumberDictionary::AtNumberPut(id_map_, id, object,
1597 used_as_prototype);
1598 1597
1599 // If the dictionary was reallocated, update the global handle. 1598 // If the dictionary was reallocated, update the global handle.
1600 if (!new_dictionary.is_identical_to(id_map_)) { 1599 if (!new_array.is_identical_to(id_map_)) {
1601 GlobalHandles::Destroy(Handle<Object>::cast(id_map_).location()); 1600 GlobalHandles::Destroy(Handle<Object>::cast(id_map_).location());
1602 id_map_ = Handle<SeededNumberDictionary>::cast( 1601 id_map_ = Handle<FixedArray>::cast(
1603 isolate_->global_handles()->Create(*new_dictionary)); 1602 isolate_->global_handles()->Create(*new_array));
1604 } 1603 }
1605 } 1604 }
1606 1605
1607 static Maybe<bool> SetPropertiesFromKeyValuePairs(Isolate* isolate, 1606 static Maybe<bool> SetPropertiesFromKeyValuePairs(Isolate* isolate,
1608 Handle<JSObject> object, 1607 Handle<JSObject> object,
1609 Handle<Object>* data, 1608 Handle<Object>* data,
1610 uint32_t num_properties) { 1609 uint32_t num_properties) {
1611 for (unsigned i = 0; i < 2 * num_properties; i += 2) { 1610 for (unsigned i = 0; i < 2 * num_properties; i += 2) {
1612 Handle<Object> key = data[i]; 1611 Handle<Object> key = data[i];
1613 Handle<Object> value = data[i + 1]; 1612 Handle<Object> value = data[i + 1];
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 if (stack.size() != 1) { 1711 if (stack.size() != 1) {
1713 isolate_->Throw(*isolate_->factory()->NewError( 1712 isolate_->Throw(*isolate_->factory()->NewError(
1714 MessageTemplate::kDataCloneDeserializationError)); 1713 MessageTemplate::kDataCloneDeserializationError));
1715 return MaybeHandle<Object>(); 1714 return MaybeHandle<Object>();
1716 } 1715 }
1717 return scope.CloseAndEscape(stack[0]); 1716 return scope.CloseAndEscape(stack[0]);
1718 } 1717 }
1719 1718
1720 } // namespace internal 1719 } // namespace internal
1721 } // namespace v8 1720 } // namespace v8
OLDNEW
« no previous file with comments | « src/value-serializer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698