Permalink
Browse files

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.
  • Loading branch information...
1 parent a1a7fe5 commit 83d5ba8a150677e08fd755c605a24f322113d8e7 @cowboyd committed Sep 19, 2012
Showing with 5 additions and 16 deletions.
  1. +5 −14 ext/v8/backref.cc
  2. +0 −2 ext/v8/rr.h
View
19 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<v8::Value> Backref::toExternal() {
v8::Local<v8::Value> wrapper = v8::External::Wrap(this);
v8::Persistent<v8::Value>::New(wrapper).MakeWeak(this, &release);
View
2 ext/v8/rr.h
@@ -268,8 +268,6 @@ class Backref {
v8::Handle<v8::Value> toExternal();
static void release(v8::Persistent<v8::Value> handle, void* data);
private:
- void allocate(VALUE data);
- void deallocate();
VALUE storage;
static VALUE Storage;
static ID _new;

0 comments on commit 83d5ba8

Please sign in to comment.