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

Unified Diff: runtime/vm/object.cc

Issue 10945020: Add virtual method to Object to ease dictionary code (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
===================================================================
--- runtime/vm/object.cc (revision 12576)
+++ runtime/vm/object.cc (working copy)
@@ -1105,6 +1105,11 @@
}
+RawString* Object::DictionaryName() const {
+ return String::null();
+}
+
+
void Object::InitializeObject(uword address, intptr_t class_id, intptr_t size) {
// TODO(iposva): Get a proper halt instruction from the assembler which
// would be needed here for code objects.
@@ -5999,28 +6004,11 @@
Object& entry = Class::Handle();
String& entry_name = String::Handle();
Object& new_entry = Object::Handle();
- Class& cls = Class::Handle();
- Function& func = Function::Handle();
- Field& field = Field::Handle();
- LibraryPrefix& prefix = LibraryPrefix::Handle();
for (intptr_t i = 0; i < dict_size; i++) {
entry = dict.At(i);
if (!entry.IsNull()) {
- if (entry.IsClass()) {
- cls ^= entry.raw();
- entry_name = cls.Name();
- } else if (entry.IsFunction()) {
- func ^= entry.raw();
- entry_name = func.name();
- } else if (entry.IsField()) {
- field ^= entry.raw();
- entry_name = field.name();
- } else if (entry.IsLibraryPrefix()) {
- prefix ^= entry.raw();
- entry_name = prefix.name();
- } else {
- UNREACHABLE();
- }
+ entry_name = entry.DictionaryName();
+ ASSERT(!entry_name.IsNull());
intptr_t hash = entry_name.Hash();
intptr_t index = hash % new_dict_size;
new_entry = new_dict.At(index);
@@ -6044,11 +6032,8 @@
obj.IsFunction() ||
obj.IsField() ||
obj.IsLibraryPrefix());
- ASSERT((LookupLocalObject(name) == Object::null()) ||
- ((obj.IsLibraryPrefix() ||
- (obj.IsClass() &&
- Class::CheckedHandle(obj.raw()).IsCanonicalSignatureClass())) &&
- (LookupLocalObject(name) == Object::null())));
+ ASSERT(name.Equals(String::Handle(obj.DictionaryName())));
+ ASSERT(LookupLocalObject(name) == Object::null());
const Array& dict = Array::Handle(dictionary());
intptr_t dict_size = dict.Length() - 1;
intptr_t index = name.Hash() % dict_size;
@@ -6092,18 +6077,9 @@
entry = dict.At(*index);
// Search the entry in the hash set.
while (!entry.IsNull()) {
- if (entry.IsClass()) {
- entry_name = Class::Cast(entry).Name();
- } else if (entry.IsFunction()) {
- entry_name = Function::Cast(entry).name();
- } else if (entry.IsField()) {
- entry_name = Field::Cast(entry).name();
- } else if (entry.IsLibraryPrefix()) {
- entry_name = LibraryPrefix::Cast(entry).name();
- } else {
- UNREACHABLE();
- }
- if (entry_name.Equals(name)) {
+ entry_name = entry.DictionaryName();
+ ASSERT(!entry_name.IsNull());
+ if (entry_name.Equals(name)) {
return entry.raw();
}
*index = (*index + 1) % dict_size;
« no previous file with comments | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698