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

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

Issue 1477573002: Remove Field::FindFieldIndex() and update service protocol (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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/object_test.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 (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 3056 matching lines...) Expand 10 before | Expand all | Expand 10 after
3067 const intptr_t num_old_fields = arr.Length(); 3067 const intptr_t num_old_fields = arr.Length();
3068 const Array& new_arr = Array::Handle( 3068 const Array& new_arr = Array::Handle(
3069 Array::Grow(arr, num_old_fields + num_new_fields, Heap::kOld)); 3069 Array::Grow(arr, num_old_fields + num_new_fields, Heap::kOld));
3070 for (intptr_t i = 0; i < num_new_fields; i++) { 3070 for (intptr_t i = 0; i < num_new_fields; i++) {
3071 new_arr.SetAt(i + num_old_fields, *new_fields.At(i)); 3071 new_arr.SetAt(i + num_old_fields, *new_fields.At(i));
3072 } 3072 }
3073 SetFields(new_arr); 3073 SetFields(new_arr);
3074 } 3074 }
3075 3075
3076 3076
3077 intptr_t Class::FindFieldIndex(const Field& needle) const {
3078 Thread* thread = Thread::Current();
3079 if (EnsureIsFinalized(thread) != Error::null()) {
3080 return -1;
3081 }
3082 REUSABLE_ARRAY_HANDLESCOPE(thread);
3083 REUSABLE_FIELD_HANDLESCOPE(thread);
3084 REUSABLE_STRING_HANDLESCOPE(thread);
3085 Array& fields_array = thread->ArrayHandle();
3086 Field& field = thread->FieldHandle();
3087 String& field_name = thread->StringHandle();
3088 fields_array ^= fields();
3089 ASSERT(!fields_array.IsNull());
3090 String& needle_name = String::Handle(thread->zone());
3091 needle_name ^= needle.name();
3092 const intptr_t len = fields_array.Length();
3093 for (intptr_t i = 0; i < len; i++) {
3094 field ^= fields_array.At(i);
3095 field_name ^= field.name();
3096 if (field_name.Equals(needle_name)) {
3097 return i;
3098 }
3099 }
3100 // No field found.
3101 return -1;
3102 }
3103
3104
3105 RawField* Class::FieldFromIndex(intptr_t idx) const {
3106 const Array& flds = Array::Handle(fields());
3107 if ((idx < 0) || (idx >= flds.Length())) {
3108 return Field::null();
3109 }
3110 Field& field = Field::Handle();
3111 field ^= flds.At(idx);
3112 ASSERT(!field.IsNull());
3113 return field.raw();
3114 }
3115
3116
3117 template <class FakeInstance> 3077 template <class FakeInstance>
3118 RawClass* Class::New(intptr_t index) { 3078 RawClass* Class::New(intptr_t index) {
3119 ASSERT(Object::class_class() != Class::null()); 3079 ASSERT(Object::class_class() != Class::null());
3120 Class& result = Class::Handle(); 3080 Class& result = Class::Handle();
3121 { 3081 {
3122 RawObject* raw = Object::Allocate(Class::kClassId, 3082 RawObject* raw = Object::Allocate(Class::kClassId,
3123 Class::InstanceSize(), 3083 Class::InstanceSize(),
3124 Heap::kOld); 3084 Heap::kOld);
3125 NoSafepointScope no_safepoint; 3085 NoSafepointScope no_safepoint;
3126 result ^= raw; 3086 result ^= raw;
(...skipping 4427 matching lines...) Expand 10 before | Expand all | Expand 10 after
7554 const char* kF0 = is_static() ? " static" : ""; 7514 const char* kF0 = is_static() ? " static" : "";
7555 const char* kF1 = is_final() ? " final" : ""; 7515 const char* kF1 = is_final() ? " final" : "";
7556 const char* kF2 = is_const() ? " const" : ""; 7516 const char* kF2 = is_const() ? " const" : "";
7557 const char* field_name = String::Handle(name()).ToCString(); 7517 const char* field_name = String::Handle(name()).ToCString();
7558 const Class& cls = Class::Handle(owner()); 7518 const Class& cls = Class::Handle(owner());
7559 const char* cls_name = String::Handle(cls.Name()).ToCString(); 7519 const char* cls_name = String::Handle(cls.Name()).ToCString();
7560 return OS::SCreate(Thread::Current()->zone(), 7520 return OS::SCreate(Thread::Current()->zone(),
7561 "Field <%s.%s>:%s%s%s", cls_name, field_name, kF0, kF1, kF2); 7521 "Field <%s.%s>:%s%s%s", cls_name, field_name, kF0, kF1, kF2);
7562 } 7522 }
7563 7523
7524
7564 void Field::PrintJSONImpl(JSONStream* stream, bool ref) const { 7525 void Field::PrintJSONImpl(JSONStream* stream, bool ref) const {
7565 JSONObject jsobj(stream); 7526 JSONObject jsobj(stream);
7566 Class& cls = Class::Handle(owner()); 7527 Class& cls = Class::Handle(owner());
7567 intptr_t id = cls.FindFieldIndex(*this); 7528 String& field_name = String::Handle(name());
7568 ASSERT(id >= 0); 7529 ASSERT(cls.LookupField(field_name) == this->raw());
7569 intptr_t cid = cls.id(); 7530 field_name = String::EncodeIRI(field_name);
7570 AddCommonObjectProperties(&jsobj, "Field", ref); 7531 AddCommonObjectProperties(&jsobj, "Field", ref);
7571 jsobj.AddFixedServiceId("classes/%" Pd "/fields/%" Pd "", cid, id); 7532 jsobj.AddFixedServiceId("classes/%" Pd "/fields/%s",
7533 cls.id(), field_name.ToCString());
7534
7572 const String& user_name = String::Handle(PrettyName()); 7535 const String& user_name = String::Handle(PrettyName());
7573 const String& vm_name = String::Handle(name()); 7536 const String& vm_name = String::Handle(name());
7574 AddNameProperties(&jsobj, user_name, vm_name); 7537 AddNameProperties(&jsobj, user_name, vm_name);
7575 if (cls.IsTopLevel()) { 7538 if (cls.IsTopLevel()) {
7576 const Library& library = Library::Handle(cls.library()); 7539 const Library& library = Library::Handle(cls.library());
7577 jsobj.AddProperty("owner", library); 7540 jsobj.AddProperty("owner", library);
7578 } else { 7541 } else {
7579 jsobj.AddProperty("owner", cls); 7542 jsobj.AddProperty("owner", cls);
7580 } 7543 }
7581 7544
(...skipping 14325 matching lines...) Expand 10 before | Expand all | Expand 10 after
21907 return tag_label.ToCString(); 21870 return tag_label.ToCString();
21908 } 21871 }
21909 21872
21910 21873
21911 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 21874 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
21912 Instance::PrintJSONImpl(stream, ref); 21875 Instance::PrintJSONImpl(stream, ref);
21913 } 21876 }
21914 21877
21915 21878
21916 } // namespace dart 21879 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698