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

Side by Side Diff: src/parser.cc

Issue 3144002: Copy-on-write arrays. (Closed)
Patch Set: Review fixes. Created 10 years, 4 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/parser.h ('k') | src/runtime.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 3443 matching lines...) Expand 10 before | Expand all | Expand 10 after
3454 } 3454 }
3455 Handle<Object> boilerplate_value = GetBoilerplateValue(values.at(i)); 3455 Handle<Object> boilerplate_value = GetBoilerplateValue(values.at(i));
3456 if (boilerplate_value->IsUndefined()) { 3456 if (boilerplate_value->IsUndefined()) {
3457 literals->set_the_hole(i); 3457 literals->set_the_hole(i);
3458 is_simple = false; 3458 is_simple = false;
3459 } else { 3459 } else {
3460 literals->set(i, *boilerplate_value); 3460 literals->set(i, *boilerplate_value);
3461 } 3461 }
3462 } 3462 }
3463 3463
3464 // Simple and shallow arrays can be lazily copied, we transform the
3465 // elements array to a copy-on-write array.
3466 if (is_simple && depth == 1 && values.length() > 0) {
3467 literals->set_map(Heap::fixed_cow_array_map());
3468 }
3469
3464 return NEW(ArrayLiteral(literals, values.elements(), 3470 return NEW(ArrayLiteral(literals, values.elements(),
3465 literal_index, is_simple, depth)); 3471 literal_index, is_simple, depth));
3466 } 3472 }
3467 3473
3468 3474
3469 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) { 3475 bool Parser::IsBoilerplateProperty(ObjectLiteral::Property* property) {
3470 return property != NULL && 3476 return property != NULL &&
3471 property->kind() != ObjectLiteral::Property::PROTOTYPE; 3477 property->kind() != ObjectLiteral::Property::PROTOTYPE;
3472 } 3478 }
3473 3479
3474 3480
3475 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) { 3481 bool CompileTimeValue::IsCompileTimeValue(Expression* expression) {
3476 MaterializedLiteral* lit = expression->AsMaterializedLiteral(); 3482 MaterializedLiteral* lit = expression->AsMaterializedLiteral();
3477 return lit != NULL && lit->is_simple(); 3483 return lit != NULL && lit->is_simple();
3478 } 3484 }
3479 3485
3486
3487 bool CompileTimeValue::ArrayLiteralElementNeedsInitialization(
3488 Expression* value) {
3489 // If value is a literal the property value is already set in the
3490 // boilerplate object.
3491 if (value->AsLiteral() != NULL) return false;
3492 // If value is a materialized literal the property value is already set
3493 // in the boilerplate object if it is simple.
3494 if (CompileTimeValue::IsCompileTimeValue(value)) return false;
3495 return true;
3496 }
3497
3498
3480 Handle<FixedArray> CompileTimeValue::GetValue(Expression* expression) { 3499 Handle<FixedArray> CompileTimeValue::GetValue(Expression* expression) {
3481 ASSERT(IsCompileTimeValue(expression)); 3500 ASSERT(IsCompileTimeValue(expression));
3482 Handle<FixedArray> result = Factory::NewFixedArray(2, TENURED); 3501 Handle<FixedArray> result = Factory::NewFixedArray(2, TENURED);
3483 ObjectLiteral* object_literal = expression->AsObjectLiteral(); 3502 ObjectLiteral* object_literal = expression->AsObjectLiteral();
3484 if (object_literal != NULL) { 3503 if (object_literal != NULL) {
3485 ASSERT(object_literal->is_simple()); 3504 ASSERT(object_literal->is_simple());
3486 if (object_literal->fast_elements()) { 3505 if (object_literal->fast_elements()) {
3487 result->set(kTypeSlot, Smi::FromInt(OBJECT_LITERAL_FAST_ELEMENTS)); 3506 result->set(kTypeSlot, Smi::FromInt(OBJECT_LITERAL_FAST_ELEMENTS));
3488 } else { 3507 } else {
3489 result->set(kTypeSlot, Smi::FromInt(OBJECT_LITERAL_SLOW_ELEMENTS)); 3508 result->set(kTypeSlot, Smi::FromInt(OBJECT_LITERAL_SLOW_ELEMENTS));
(...skipping 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after
5238 parser.ParseLazy(script_source, name, 5257 parser.ParseLazy(script_source, name,
5239 start_position, end_position, is_expression); 5258 start_position, end_position, is_expression);
5240 return result; 5259 return result;
5241 } 5260 }
5242 5261
5243 5262
5244 #undef NEW 5263 #undef NEW
5245 5264
5246 5265
5247 } } // namespace v8::internal 5266 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698