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

Unified Diff: vm/object.h

Issue 11369028: Avoid duplicate null checks when calling SetRaw from InitializeHandle (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 1 month 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: vm/object.h
===================================================================
--- vm/object.h (revision 14551)
+++ vm/object.h (working copy)
@@ -150,7 +150,9 @@
virtual ~Object() { }
RawObject* raw() const { return raw_; }
- void operator=(RawObject* value) { SetRaw(value); }
+ void operator=(RawObject* value) {
+ initializeHandle(this, value);
+ }
void set_tags(intptr_t value) const {
// TODO(asiva): Remove the capability of setting tags in general. The mask
@@ -212,7 +214,7 @@
static Object& Handle(Isolate* isolate, RawObject* raw_ptr) {
Object* obj = reinterpret_cast<Object*>(VMHandles::AllocateHandle(isolate));
- obj->SetRaw(raw_ptr);
+ initializeHandle(obj, raw_ptr);
return *obj;
}
@@ -231,7 +233,7 @@
static Object& ZoneHandle(Isolate* isolate, RawObject* raw_ptr) {
Object* obj = reinterpret_cast<Object*>(
VMHandles::AllocateZoneHandle(isolate));
- obj->SetRaw(raw_ptr);
+ initializeHandle(obj, raw_ptr);
return *obj;
}
@@ -371,6 +373,17 @@
const String& name,
const Library& lib);
+ /* Initialize the handle based on the raw_ptr in the presence of null. */
+ static void initializeHandle(Object* obj, RawObject* raw_ptr) {
+ if (raw_ptr != Object::null()) {
+ obj->SetRaw(raw_ptr);
+ } else {
+ obj->raw_ = Object::null();
+ Object fake_object;
+ obj->set_vtable(fake_object.vtable());
+ }
+ }
+
cpp_vtable* vtable_address() const {
uword vtable_addr = reinterpret_cast<uword>(this);
return reinterpret_cast<cpp_vtable*>(vtable_addr);
@@ -5776,11 +5789,12 @@
if ((reinterpret_cast<uword>(raw_) & kSmiTagMask) == kSmiTag) {
set_vtable(Smi::handle_vtable_);
return;
- } else if (raw_ == null_) {
- set_vtable(handle_vtable_);
- return;
}
-
+ intptr_t cid = raw_->GetClassId();
+ if (cid >= kNumPredefinedCids) {
+ cid = kInstanceCid;
+ }
+ set_vtable(builtin_vtables_[cid]);
#if defined(DEBUG)
Isolate* isolate = Isolate::Current();
if (FLAG_verify_handles) {
@@ -5789,17 +5803,9 @@
ASSERT(isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr())) ||
vm_isolate_heap->Contains(reinterpret_cast<uword>(raw_->ptr())));
}
+ ASSERT(builtin_vtables_[cid] ==
+ isolate->class_table()->At(cid)->ptr()->handle_vtable_);
#endif
- intptr_t cid = raw_->GetClassId();
- if (cid < kNumPredefinedCids) {
-#if defined(DEBUG)
- ASSERT(builtin_vtables_[cid] ==
- isolate->class_table()->At(cid)->ptr()->handle_vtable_);
-#endif
- set_vtable(builtin_vtables_[cid]);
- } else {
- set_vtable(builtin_vtables_[kInstanceCid]);
- }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698