From 83d5ba8a150677e08fd755c605a24f322113d8e7 Mon Sep 17 00:00:00 2001 From: Charles Lowell Date: Wed, 19 Sep 2012 15:38:59 +0300 Subject: [PATCH] remove GC histrionics in backreferences. The memory address for the storage cell does not change, only the VALUE, so there is no need to unregister and register the storage cell pointer with Ruby GC every time its value changes. --- ext/v8/backref.cc | 19 +++++-------------- ext/v8/rr.h | 2 -- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/ext/v8/backref.cc b/ext/v8/backref.cc index d0773a77..5f58c450 100644 --- a/ext/v8/backref.cc +++ b/ext/v8/backref.cc @@ -14,32 +14,23 @@ namespace rr { } Backref::Backref(VALUE initial) { - allocate(initial); + set(initial); + rb_gc_register_address(&storage); } Backref::~Backref() { - deallocate(); + rb_gc_unregister_address(&storage); } - void Backref::allocate(VALUE data) { + VALUE Backref::set(VALUE data) { this->storage = rb_funcall(Storage, _new, 1, data); - rb_gc_register_address(&storage); - } - - void Backref::deallocate() { - rb_gc_unregister_address(&storage); + return data; } VALUE Backref::get() { return rb_funcall(storage, object, 0); } - VALUE Backref::set(VALUE data) { - deallocate(); - allocate(data); - return data; - } - v8::Handle Backref::toExternal() { v8::Local wrapper = v8::External::Wrap(this); v8::Persistent::New(wrapper).MakeWeak(this, &release); diff --git a/ext/v8/rr.h b/ext/v8/rr.h index a8bd250b..ed852987 100644 --- a/ext/v8/rr.h +++ b/ext/v8/rr.h @@ -268,8 +268,6 @@ class Backref { v8::Handle toExternal(); static void release(v8::Persistent handle, void* data); private: - void allocate(VALUE data); - void deallocate(); VALUE storage; static VALUE Storage; static ID _new;