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

Side by Side Diff: runtime/vm/object.cc

Issue 1313363005: Use zone allocated C-strings instead of String heap objects to construct signature symbols (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Address comments Created 5 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 | « runtime/vm/object.h ('k') | runtime/vm/symbols.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 (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 6459 matching lines...) Expand 10 before | Expand all | Expand 10 after
6470 signature_class, signature_type, ClassFinalizer::kCanonicalize); 6470 signature_class, signature_type, ClassFinalizer::kCanonicalize);
6471 } 6471 }
6472 ASSERT(closure_function.signature_class() == signature_class.raw()); 6472 ASSERT(closure_function.signature_class() == signature_class.raw());
6473 set_implicit_closure_function(closure_function); 6473 set_implicit_closure_function(closure_function);
6474 ASSERT(closure_function.IsImplicitClosureFunction()); 6474 ASSERT(closure_function.IsImplicitClosureFunction());
6475 return closure_function.raw(); 6475 return closure_function.raw();
6476 } 6476 }
6477 6477
6478 6478
6479 RawString* Function::UserVisibleFormalParameters() const { 6479 RawString* Function::UserVisibleFormalParameters() const {
6480 const GrowableObjectArray& pieces = 6480 // Typically 3, 5,.. elements in 'pieces', e.g.:
6481 GrowableObjectArray::Handle(GrowableObjectArray::New()); 6481 // '_LoadRequest', CommaSpace, '_LoadError'.
6482 GrowableArray<const String*> pieces(5);
6482 const TypeArguments& instantiator = TypeArguments::Handle(); 6483 const TypeArguments& instantiator = TypeArguments::Handle();
6483 BuildSignatureParameters(false, kUserVisibleName, instantiator, pieces); 6484 BuildSignatureParameters(false, kUserVisibleName, instantiator, &pieces);
6484 const Array& strings = Array::Handle(Array::MakeArray(pieces)); 6485 return Symbols::FromConcatAll(pieces);
6485 return String::ConcatAll(strings);
6486 } 6486 }
6487 6487
6488 6488
6489 void Function::BuildSignatureParameters( 6489 void Function::BuildSignatureParameters(
6490 bool instantiate, 6490 bool instantiate,
6491 NameVisibility name_visibility, 6491 NameVisibility name_visibility,
6492 const TypeArguments& instantiator, 6492 const TypeArguments& instantiator,
6493 const GrowableObjectArray& pieces) const { 6493 GrowableArray<const String*>* pieces) const {
6494 AbstractType& param_type = AbstractType::Handle(); 6494 Thread* thread = Thread::Current();
6495 Zone* zone = thread->zone();
6496
6497 AbstractType& param_type = AbstractType::Handle(zone);
6495 const intptr_t num_params = NumParameters(); 6498 const intptr_t num_params = NumParameters();
6496 const intptr_t num_fixed_params = num_fixed_parameters(); 6499 const intptr_t num_fixed_params = num_fixed_parameters();
6497 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters(); 6500 const intptr_t num_opt_pos_params = NumOptionalPositionalParameters();
6498 const intptr_t num_opt_named_params = NumOptionalNamedParameters(); 6501 const intptr_t num_opt_named_params = NumOptionalNamedParameters();
6499 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params; 6502 const intptr_t num_opt_params = num_opt_pos_params + num_opt_named_params;
6500 ASSERT((num_fixed_params + num_opt_params) == num_params); 6503 ASSERT((num_fixed_params + num_opt_params) == num_params);
6501 String& name = String::Handle();
6502 intptr_t i = 0; 6504 intptr_t i = 0;
6503 if (name_visibility == kUserVisibleName) { 6505 if (name_visibility == kUserVisibleName) {
6504 // Hide implicit parameters. 6506 // Hide implicit parameters.
6505 i = NumImplicitParameters(); 6507 i = NumImplicitParameters();
6506 } 6508 }
6507 while (i < num_fixed_params) { 6509 while (i < num_fixed_params) {
6508 param_type = ParameterTypeAt(i); 6510 param_type = ParameterTypeAt(i);
6509 ASSERT(!param_type.IsNull()); 6511 ASSERT(!param_type.IsNull());
6510 if (instantiate && !param_type.IsInstantiated()) { 6512 if (instantiate && !param_type.IsInstantiated()) {
6511 param_type = param_type.InstantiateFrom(instantiator, NULL); 6513 param_type = param_type.InstantiateFrom(instantiator, NULL);
6512 } 6514 }
6513 name = param_type.BuildName(name_visibility); 6515 const String& name =
6514 pieces.Add(name); 6516 String::ZoneHandle(zone, param_type.BuildName(name_visibility));
6517 pieces->Add(&name);
6515 if (i != (num_params - 1)) { 6518 if (i != (num_params - 1)) {
6516 pieces.Add(Symbols::CommaSpace()); 6519 pieces->Add(&Symbols::CommaSpace());
6517 } 6520 }
6518 i++; 6521 i++;
6519 } 6522 }
6520 if (num_opt_params > 0) { 6523 if (num_opt_params > 0) {
6521 if (num_opt_pos_params > 0) { 6524 if (num_opt_pos_params > 0) {
6522 pieces.Add(Symbols::LBracket()); 6525 pieces->Add(&Symbols::LBracket());
6523 } else { 6526 } else {
6524 pieces.Add(Symbols::LBrace()); 6527 pieces->Add(&Symbols::LBrace());
6525 } 6528 }
6526 for (intptr_t i = num_fixed_params; i < num_params; i++) { 6529 for (intptr_t i = num_fixed_params; i < num_params; i++) {
6527 // The parameter name of an optional positional parameter does not need 6530 // The parameter name of an optional positional parameter does not need
6528 // to be part of the signature, since it is not used. 6531 // to be part of the signature, since it is not used.
6529 if (num_opt_named_params > 0) { 6532 if (num_opt_named_params > 0) {
6530 name = ParameterNameAt(i); 6533 const String& name = String::ZoneHandle(zone, ParameterNameAt(i));
6531 pieces.Add(name); 6534 pieces->Add(&name);
6532 pieces.Add(Symbols::ColonSpace()); 6535 pieces->Add(&Symbols::ColonSpace());
6533 } 6536 }
6534 param_type = ParameterTypeAt(i); 6537 param_type = ParameterTypeAt(i);
6535 if (instantiate && !param_type.IsInstantiated()) { 6538 if (instantiate && !param_type.IsInstantiated()) {
6536 param_type = param_type.InstantiateFrom(instantiator, NULL); 6539 param_type = param_type.InstantiateFrom(instantiator, NULL);
6537 } 6540 }
6538 ASSERT(!param_type.IsNull()); 6541 ASSERT(!param_type.IsNull());
6539 name = param_type.BuildName(name_visibility); 6542 const String& name =
6540 pieces.Add(name); 6543 String::ZoneHandle(zone, param_type.BuildName(name_visibility));
6544 pieces->Add(&name);
6541 if (i != (num_params - 1)) { 6545 if (i != (num_params - 1)) {
6542 pieces.Add(Symbols::CommaSpace()); 6546 pieces->Add(&Symbols::CommaSpace());
6543 } 6547 }
6544 } 6548 }
6545 if (num_opt_pos_params > 0) { 6549 if (num_opt_pos_params > 0) {
6546 pieces.Add(Symbols::RBracket()); 6550 pieces->Add(&Symbols::RBracket());
6547 } else { 6551 } else {
6548 pieces.Add(Symbols::RBrace()); 6552 pieces->Add(&Symbols::RBrace());
6549 } 6553 }
6550 } 6554 }
6551 } 6555 }
6552 6556
6553 6557
6554 RawInstance* Function::ImplicitStaticClosure() const { 6558 RawInstance* Function::ImplicitStaticClosure() const {
6555 if (implicit_static_closure() == Instance::null()) { 6559 if (implicit_static_closure() == Instance::null()) {
6556 Isolate* isolate = Isolate::Current(); 6560 Isolate* isolate = Isolate::Current();
6557 ObjectStore* object_store = isolate->object_store(); 6561 ObjectStore* object_store = isolate->object_store();
6558 const Context& context = 6562 const Context& context =
(...skipping 20 matching lines...) Expand all
6579 TypeArguments::Handle(receiver.GetTypeArguments()); 6583 TypeArguments::Handle(receiver.GetTypeArguments());
6580 result.SetTypeArguments(type_arguments); 6584 result.SetTypeArguments(type_arguments);
6581 } 6585 }
6582 return result.raw(); 6586 return result.raw();
6583 } 6587 }
6584 6588
6585 6589
6586 RawString* Function::BuildSignature(bool instantiate, 6590 RawString* Function::BuildSignature(bool instantiate,
6587 NameVisibility name_visibility, 6591 NameVisibility name_visibility,
6588 const TypeArguments& instantiator) const { 6592 const TypeArguments& instantiator) const {
6589 const GrowableObjectArray& pieces = 6593 Thread* thread = Thread::Current();
6590 GrowableObjectArray::Handle(GrowableObjectArray::New()); 6594 Zone* zone = thread->zone();
6591 String& name = String::Handle(); 6595 GrowableArray<const String*> pieces(zone, 4);
6592 if (!instantiate && !is_static() && (name_visibility == kInternalName)) { 6596 if (!instantiate && !is_static() && (name_visibility == kInternalName)) {
6593 // Prefix the signature with its signature class and type parameters, if any 6597 // Prefix the signature with its signature class and type parameters, if any
6594 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the 6598 // (e.g. "Map<K, V>(K) => bool"). In case of a function type alias, the
6595 // signature class name is the alias name. 6599 // signature class name is the alias name.
6596 // The signature of static functions cannot be type parameterized. 6600 // The signature of static functions cannot be type parameterized.
6597 const Class& function_class = Class::Handle(Owner()); 6601 const Class& function_class = Class::Handle(zone, Owner());
6598 ASSERT(!function_class.IsNull()); 6602 ASSERT(!function_class.IsNull());
6599 const TypeArguments& type_parameters = TypeArguments::Handle( 6603 const TypeArguments& type_parameters = TypeArguments::Handle(
6600 function_class.type_parameters()); 6604 zone, function_class.type_parameters());
6601 if (!type_parameters.IsNull()) { 6605 if (!type_parameters.IsNull()) {
6602 const String& function_class_name = String::Handle(function_class.Name()); 6606 const String& function_class_name =
6603 pieces.Add(function_class_name); 6607 String::ZoneHandle(zone, function_class.Name());
6608 pieces.Add(&function_class_name);
6604 const intptr_t num_type_parameters = type_parameters.Length(); 6609 const intptr_t num_type_parameters = type_parameters.Length();
6605 pieces.Add(Symbols::LAngleBracket()); 6610 pieces.Add(&Symbols::LAngleBracket());
6606 TypeParameter& type_parameter = TypeParameter::Handle(); 6611 TypeParameter& type_parameter = TypeParameter::Handle(zone);
6607 AbstractType& bound = AbstractType::Handle(); 6612 AbstractType& bound = AbstractType::Handle(zone);
6608 for (intptr_t i = 0; i < num_type_parameters; i++) { 6613 for (intptr_t i = 0; i < num_type_parameters; i++) {
6609 type_parameter ^= type_parameters.TypeAt(i); 6614 type_parameter ^= type_parameters.TypeAt(i);
6610 name = type_parameter.name(); 6615 const String& name = String::ZoneHandle(zone, type_parameter.name());
6611 pieces.Add(name); 6616 pieces.Add(&name);
6612 bound = type_parameter.bound(); 6617 bound = type_parameter.bound();
6613 if (!bound.IsNull() && !bound.IsObjectType()) { 6618 if (!bound.IsNull() && !bound.IsObjectType()) {
6614 pieces.Add(Symbols::SpaceExtendsSpace()); 6619 pieces.Add(&Symbols::SpaceExtendsSpace());
6615 name = bound.BuildName(name_visibility); 6620 const String& name =
6616 pieces.Add(name); 6621 String::ZoneHandle(zone, bound.BuildName(name_visibility));
6622 pieces.Add(&name);
6617 } 6623 }
6618 if (i < num_type_parameters - 1) { 6624 if (i < num_type_parameters - 1) {
6619 pieces.Add(Symbols::CommaSpace()); 6625 pieces.Add(&Symbols::CommaSpace());
6620 } 6626 }
6621 } 6627 }
6622 pieces.Add(Symbols::RAngleBracket()); 6628 pieces.Add(&Symbols::RAngleBracket());
6623 } 6629 }
6624 } 6630 }
6625 pieces.Add(Symbols::LParen()); 6631 pieces.Add(&Symbols::LParen());
6626 BuildSignatureParameters(instantiate, 6632 BuildSignatureParameters(instantiate,
6627 name_visibility, 6633 name_visibility,
6628 instantiator, 6634 instantiator,
6629 pieces); 6635 &pieces);
6630 pieces.Add(Symbols::RParenArrow()); 6636 pieces.Add(&Symbols::RParenArrow());
6631 AbstractType& res_type = AbstractType::Handle(result_type()); 6637 AbstractType& res_type = AbstractType::Handle(zone, result_type());
6632 if (instantiate && !res_type.IsInstantiated()) { 6638 if (instantiate && !res_type.IsInstantiated()) {
6633 res_type = res_type.InstantiateFrom(instantiator, NULL); 6639 res_type = res_type.InstantiateFrom(instantiator, NULL);
6634 } 6640 }
6635 name = res_type.BuildName(name_visibility); 6641 const String& name =
6636 pieces.Add(name); 6642 String::ZoneHandle(zone, res_type.BuildName(name_visibility));
6637 const Array& strings = Array::Handle(Array::MakeArray(pieces)); 6643 pieces.Add(&name);
6638 return Symbols::New(String::Handle(String::ConcatAll(strings))); 6644 return Symbols::FromConcatAll(pieces);
6639 } 6645 }
6640 6646
6641 6647
6642 bool Function::HasInstantiatedSignature() const { 6648 bool Function::HasInstantiatedSignature() const {
6643 AbstractType& type = AbstractType::Handle(result_type()); 6649 AbstractType& type = AbstractType::Handle(result_type());
6644 if (!type.IsInstantiated()) { 6650 if (!type.IsInstantiated()) {
6645 return false; 6651 return false;
6646 } 6652 }
6647 const intptr_t num_parameters = NumParameters(); 6653 const intptr_t num_parameters = NumParameters();
6648 for (intptr_t i = 0; i < num_parameters; i++) { 6654 for (intptr_t i = 0; i < num_parameters; i++) {
(...skipping 14772 matching lines...) Expand 10 before | Expand all | Expand 10 after
21421 return tag_label.ToCString(); 21427 return tag_label.ToCString();
21422 } 21428 }
21423 21429
21424 21430
21425 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 21431 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
21426 Instance::PrintJSONImpl(stream, ref); 21432 Instance::PrintJSONImpl(stream, ref);
21427 } 21433 }
21428 21434
21429 21435
21430 } // namespace dart 21436 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/symbols.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698