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

Commit 83d5ba8

Browse files
committed
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.
1 parent a1a7fe5 commit 83d5ba8

2 files changed

Lines changed: 5 additions & 16 deletions

File tree

ext/v8/backref.cc

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,23 @@ namespace rr {
1414
}
1515

1616
Backref::Backref(VALUE initial) {
17-
allocate(initial);
17+
set(initial);
18+
rb_gc_register_address(&storage);
1819
}
1920

2021
Backref::~Backref() {
21-
deallocate();
22+
rb_gc_unregister_address(&storage);
2223
}
2324

24-
void Backref::allocate(VALUE data) {
25+
VALUE Backref::set(VALUE data) {
2526
this->storage = rb_funcall(Storage, _new, 1, data);
26-
rb_gc_register_address(&storage);
27-
}
28-
29-
void Backref::deallocate() {
30-
rb_gc_unregister_address(&storage);
27+
return data;
3128
}
3229

3330
VALUE Backref::get() {
3431
return rb_funcall(storage, object, 0);
3532
}
3633

37-
VALUE Backref::set(VALUE data) {
38-
deallocate();
39-
allocate(data);
40-
return data;
41-
}
42-
4334
v8::Handle<v8::Value> Backref::toExternal() {
4435
v8::Local<v8::Value> wrapper = v8::External::Wrap(this);
4536
v8::Persistent<v8::Value>::New(wrapper).MakeWeak(this, &release);

ext/v8/rr.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,6 @@ class Backref {
268268
v8::Handle<v8::Value> toExternal();
269269
static void release(v8::Persistent<v8::Value> handle, void* data);
270270
private:
271-
void allocate(VALUE data);
272-
void deallocate();
273271
VALUE storage;
274272
static VALUE Storage;
275273
static ID _new;

0 commit comments

Comments
 (0)