smalloc: don't do Has(key), then Get(key)
authorBen Noordhuis <info@bnoordhuis.nl>
Thu, 15 Aug 2013 14:41:19 +0000 (16:41 +0200)
committerBen Noordhuis <info@bnoordhuis.nl>
Thu, 15 Aug 2013 14:47:54 +0000 (16:47 +0200)
Don't check for the key first before retrieving it. Just fetch it and
check that it has the type we expect.

src/smalloc.cc

index c4c1663..8100fbf 100644 (file)
@@ -301,11 +301,14 @@ void AllocDispose(const FunctionCallbackInfo<Value>& args) {
 void AllocDispose(Handle<Object> obj) {
   HandleScope scope(node_isolate);
 
-  if (using_alloc_cb && obj->Has(smalloc_sym)) {
-    Local<External> ext = obj->GetHiddenValue(smalloc_sym).As<External>();
-    CallbackInfo* cb_info = static_cast<CallbackInfo*>(ext->Value());
-    TargetFreeCallback(node_isolate, &cb_info->p_obj, cb_info);
-    return;
+  if (using_alloc_cb) {
+    Local<Value> ext_v = obj->GetHiddenValue(smalloc_sym);
+    if (ext_v->IsExternal()) {
+      Local<External> ext = ext_v.As<External>();
+      CallbackInfo* cb_info = static_cast<CallbackInfo*>(ext->Value());
+      TargetFreeCallback(node_isolate, &cb_info->p_obj, cb_info);
+      return;
+    }
   }
 
   char* data = static_cast<char*>(obj->GetIndexedPropertiesExternalArrayData());