Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Commit

Permalink
remove GC histrionics in backreferences.
Browse files Browse the repository at this point in the history
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
cowboyd committed Sep 19, 2012
1 parent a1a7fe5 commit 83d5ba8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
19 changes: 5 additions & 14 deletions ext/v8/backref.cc
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions ext/v8/rr.h
Expand Up @@ -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;
Expand Down

0 comments on commit 83d5ba8

Please sign in to comment.