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

Side by Side Diff: src/runtime.cc

Issue 150168: Removed virtual behavior from Dictionaries. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 11 years, 5 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
OLDNEW
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 for (int i = 0; i < elements->length(); i++) { 161 for (int i = 0; i < elements->length(); i++) {
162 Object* value = elements->get(i); 162 Object* value = elements->get(i);
163 if (value->IsJSObject()) { 163 if (value->IsJSObject()) {
164 JSObject* jsObject = JSObject::cast(value); 164 JSObject* jsObject = JSObject::cast(value);
165 result = DeepCopyBoilerplate(jsObject); 165 result = DeepCopyBoilerplate(jsObject);
166 if (result->IsFailure()) return result; 166 if (result->IsFailure()) return result;
167 elements->set(i, result, mode); 167 elements->set(i, result, mode);
168 } 168 }
169 } 169 }
170 } else { 170 } else {
171 Dictionary* element_dictionary = copy->element_dictionary(); 171 NumberDictionary* element_dictionary = copy->element_dictionary();
172 int capacity = element_dictionary->Capacity(); 172 int capacity = element_dictionary->Capacity();
173 for (int i = 0; i < capacity; i++) { 173 for (int i = 0; i < capacity; i++) {
174 Object* k = element_dictionary->KeyAt(i); 174 Object* k = element_dictionary->KeyAt(i);
175 if (element_dictionary->IsKey(k)) { 175 if (element_dictionary->IsKey(k)) {
176 Object* value = element_dictionary->ValueAt(i); 176 Object* value = element_dictionary->ValueAt(i);
177 if (value->IsJSObject()) { 177 if (value->IsJSObject()) {
178 JSObject* jsObject = JSObject::cast(value); 178 JSObject* jsObject = JSObject::cast(value);
179 result = DeepCopyBoilerplate(jsObject); 179 result = DeepCopyBoilerplate(jsObject);
180 if (result->IsFailure()) return result; 180 if (result->IsFailure()) return result;
181 element_dictionary->ValueAtPut(i, result); 181 element_dictionary->ValueAtPut(i, result);
(...skipping 2415 matching lines...) Expand 10 before | Expand all | Expand 10 after
2597 LookupResult result; 2597 LookupResult result;
2598 receiver->LocalLookup(key, &result); 2598 receiver->LocalLookup(key, &result);
2599 if (result.IsProperty() && result.IsLoaded() && result.type() == FIELD) { 2599 if (result.IsProperty() && result.IsLoaded() && result.type() == FIELD) {
2600 int offset = result.GetFieldIndex(); 2600 int offset = result.GetFieldIndex();
2601 KeyedLookupCache::Update(receiver_map, key, offset); 2601 KeyedLookupCache::Update(receiver_map, key, offset);
2602 Object* value = receiver->FastPropertyAt(offset); 2602 Object* value = receiver->FastPropertyAt(offset);
2603 return value->IsTheHole() ? Heap::undefined_value() : value; 2603 return value->IsTheHole() ? Heap::undefined_value() : value;
2604 } 2604 }
2605 } else { 2605 } else {
2606 // Attempt dictionary lookup. 2606 // Attempt dictionary lookup.
2607 Dictionary* dictionary = receiver->property_dictionary(); 2607 StringDictionary* dictionary = receiver->property_dictionary();
2608 int entry = dictionary->FindStringEntry(key); 2608 int entry = dictionary->FindEntry(key);
2609 if ((entry != Dictionary::kNotFound) && 2609 if ((entry != StringDictionary::kNotFound) &&
2610 (dictionary->DetailsAt(entry).type() == NORMAL)) { 2610 (dictionary->DetailsAt(entry).type() == NORMAL)) {
2611 Object* value = dictionary->ValueAt(entry); 2611 Object* value = dictionary->ValueAt(entry);
2612 if (receiver->IsGlobalObject()) { 2612 if (receiver->IsGlobalObject()) {
2613 value = JSGlobalPropertyCell::cast(value)->value(); 2613 value = JSGlobalPropertyCell::cast(value)->value();
2614 } 2614 }
2615 return value; 2615 return value;
2616 } 2616 }
2617 } 2617 }
2618 } 2618 }
2619 2619
(...skipping 2503 matching lines...) Expand 10 before | Expand all | Expand 10 after
5123 5123
5124 void visit(uint32_t i, Handle<Object> elm) { 5124 void visit(uint32_t i, Handle<Object> elm) {
5125 uint32_t index = i + index_offset_; 5125 uint32_t index = i + index_offset_;
5126 if (index >= index_limit_) return; 5126 if (index >= index_limit_) return;
5127 5127
5128 if (fast_elements_) { 5128 if (fast_elements_) {
5129 ASSERT(index < static_cast<uint32_t>(storage_->length())); 5129 ASSERT(index < static_cast<uint32_t>(storage_->length()));
5130 storage_->set(index, *elm); 5130 storage_->set(index, *elm);
5131 5131
5132 } else { 5132 } else {
5133 Handle<Dictionary> dict = Handle<Dictionary>::cast(storage_); 5133 Handle<NumberDictionary> dict = Handle<NumberDictionary>::cast(storage_);
5134 Handle<Dictionary> result = 5134 Handle<NumberDictionary> result =
5135 Factory::DictionaryAtNumberPut(dict, index, elm); 5135 Factory::DictionaryAtNumberPut(dict, index, elm);
5136 if (!result.is_identical_to(dict)) 5136 if (!result.is_identical_to(dict))
5137 storage_ = result; 5137 storage_ = result;
5138 } 5138 }
5139 } 5139 }
5140 5140
5141 void increase_index_offset(uint32_t delta) { 5141 void increase_index_offset(uint32_t delta) {
5142 index_offset_ += delta; 5142 index_offset_ += delta;
5143 } 5143 }
5144 5144
(...skipping 27 matching lines...) Expand all
5172 for (uint32_t j = 0; j < len; j++) { 5172 for (uint32_t j = 0; j < len; j++) {
5173 Handle<Object> e(elements->get(j)); 5173 Handle<Object> e(elements->get(j));
5174 if (!e->IsTheHole()) { 5174 if (!e->IsTheHole()) {
5175 num_of_elements++; 5175 num_of_elements++;
5176 if (visitor) 5176 if (visitor)
5177 visitor->visit(j, e); 5177 visitor->visit(j, e);
5178 } 5178 }
5179 } 5179 }
5180 5180
5181 } else { 5181 } else {
5182 Handle<Dictionary> dict(receiver->element_dictionary()); 5182 Handle<NumberDictionary> dict(receiver->element_dictionary());
5183 uint32_t capacity = dict->Capacity(); 5183 uint32_t capacity = dict->Capacity();
5184 for (uint32_t j = 0; j < capacity; j++) { 5184 for (uint32_t j = 0; j < capacity; j++) {
5185 Handle<Object> k(dict->KeyAt(j)); 5185 Handle<Object> k(dict->KeyAt(j));
5186 if (dict->IsKey(*k)) { 5186 if (dict->IsKey(*k)) {
5187 ASSERT(k->IsNumber()); 5187 ASSERT(k->IsNumber());
5188 uint32_t index = static_cast<uint32_t>(k->Number()); 5188 uint32_t index = static_cast<uint32_t>(k->Number());
5189 if (index < range) { 5189 if (index < range) {
5190 num_of_elements++; 5190 num_of_elements++;
5191 if (visitor) { 5191 if (visitor) {
5192 visitor->visit(index, 5192 visitor->visit(index,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
5326 if (fast_case) { 5326 if (fast_case) {
5327 // The backing storage array must have non-existing elements to 5327 // The backing storage array must have non-existing elements to
5328 // preserve holes across concat operations. 5328 // preserve holes across concat operations.
5329 storage = Factory::NewFixedArrayWithHoles(result_length); 5329 storage = Factory::NewFixedArrayWithHoles(result_length);
5330 5330
5331 } else { 5331 } else {
5332 // TODO(126): move 25% pre-allocation logic into Dictionary::Allocate 5332 // TODO(126): move 25% pre-allocation logic into Dictionary::Allocate
5333 uint32_t at_least_space_for = estimate_nof_elements + 5333 uint32_t at_least_space_for = estimate_nof_elements +
5334 (estimate_nof_elements >> 2); 5334 (estimate_nof_elements >> 2);
5335 storage = Handle<FixedArray>::cast( 5335 storage = Handle<FixedArray>::cast(
5336 Factory::NewDictionary(at_least_space_for)); 5336 Factory::NewNumberDictionary(at_least_space_for));
5337 } 5337 }
5338 5338
5339 Handle<Object> len = Factory::NewNumber(static_cast<double>(result_length)); 5339 Handle<Object> len = Factory::NewNumber(static_cast<double>(result_length));
5340 5340
5341 ArrayConcatVisitor visitor(storage, result_length, fast_case); 5341 ArrayConcatVisitor visitor(storage, result_length, fast_case);
5342 5342
5343 IterateArguments(arguments, &visitor); 5343 IterateArguments(arguments, &visitor);
5344 5344
5345 result->set_length(*len); 5345 result->set_length(*len);
5346 result->set_elements(*storage); 5346 result->set_elements(*storage);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
5389 return to; 5389 return to;
5390 } 5390 }
5391 5391
5392 5392
5393 // How many elements does this array have? 5393 // How many elements does this array have?
5394 static Object* Runtime_EstimateNumberOfElements(Arguments args) { 5394 static Object* Runtime_EstimateNumberOfElements(Arguments args) {
5395 ASSERT(args.length() == 1); 5395 ASSERT(args.length() == 1);
5396 CONVERT_CHECKED(JSArray, array, args[0]); 5396 CONVERT_CHECKED(JSArray, array, args[0]);
5397 HeapObject* elements = array->elements(); 5397 HeapObject* elements = array->elements();
5398 if (elements->IsDictionary()) { 5398 if (elements->IsDictionary()) {
5399 return Smi::FromInt(Dictionary::cast(elements)->NumberOfElements()); 5399 return Smi::FromInt(NumberDictionary::cast(elements)->NumberOfElements());
5400 } else { 5400 } else {
5401 return array->length(); 5401 return array->length();
5402 } 5402 }
5403 } 5403 }
5404 5404
5405 5405
5406 // Returns an array that tells you where in the [0, length) interval an array 5406 // Returns an array that tells you where in the [0, length) interval an array
5407 // might have elements. Can either return keys or intervals. Keys can have 5407 // might have elements. Can either return keys or intervals. Keys can have
5408 // gaps in (undefined). Intervals can also span over some undefined keys. 5408 // gaps in (undefined). Intervals can also span over some undefined keys.
5409 static Object* Runtime_GetArrayKeys(Arguments args) { 5409 static Object* Runtime_GetArrayKeys(Arguments args) {
(...skipping 2126 matching lines...) Expand 10 before | Expand all | Expand 10 after
7536 } else { 7536 } else {
7537 // Handle last resort GC and make sure to allow future allocations 7537 // Handle last resort GC and make sure to allow future allocations
7538 // to grow the heap without causing GCs (if possible). 7538 // to grow the heap without causing GCs (if possible).
7539 Counters::gc_last_resort_from_js.Increment(); 7539 Counters::gc_last_resort_from_js.Increment();
7540 Heap::CollectAllGarbage(); 7540 Heap::CollectAllGarbage();
7541 } 7541 }
7542 } 7542 }
7543 7543
7544 7544
7545 } } // namespace v8::internal 7545 } } // namespace v8::internal
OLDNEW
« src/objects.cc ('K') | « src/objects-inl.h ('k') | src/stub-cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698