зеркало из https://github.com/github/ruby.git
gc.c: refactoring to rename variables
* gc.c (wmap_final_func): rename variables to clarify the meaning. In wmap2obj the key is WeakRef and the value is referenced object. In obj2wmap the key is referenced object and the value is an array of WeakRef. * gc.c (wmap_finalize): ditto. [ruby-core:49044] [Bug #7304] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
1cdeab5cdd
Коммит
7b298723b0
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
||||||
|
Sat Nov 24 21:08:50 2012 Hiroshi Shirosaki <h.shirosaki@gmail.com>
|
||||||
|
|
||||||
|
* gc.c (wmap_final_func): rename variables to clarify the meaning.
|
||||||
|
In wmap2obj the key is WeakRef and the value is referenced object.
|
||||||
|
In obj2wmap the key is referenced object and the value is an array
|
||||||
|
of WeakRef.
|
||||||
|
|
||||||
|
* gc.c (wmap_finalize): ditto.
|
||||||
|
[ruby-core:49044] [Bug #7304]
|
||||||
|
|
||||||
Sat Nov 24 21:01:55 2012 Hiroshi Shirosaki <h.shirosaki@gmail.com>
|
Sat Nov 24 21:01:55 2012 Hiroshi Shirosaki <h.shirosaki@gmail.com>
|
||||||
|
|
||||||
* array.c (rb_ary_delete_same_obj): new function for WeakRef.
|
* array.c (rb_ary_delete_same_obj): new function for WeakRef.
|
||||||
|
|
29
gc.c
29
gc.c
|
@ -3749,39 +3749,40 @@ wmap_allocate(VALUE klass)
|
||||||
static int
|
static int
|
||||||
wmap_final_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
|
wmap_final_func(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
|
||||||
{
|
{
|
||||||
VALUE obj, ary;
|
VALUE wmap, ary;
|
||||||
if (!existing) return ST_STOP;
|
if (!existing) return ST_STOP;
|
||||||
obj = (VALUE)arg, ary = (VALUE)*value;
|
wmap = (VALUE)arg, ary = (VALUE)*value;
|
||||||
rb_ary_delete_same_obj(ary, obj);
|
rb_ary_delete_same_obj(ary, wmap);
|
||||||
if (!RARRAY_LEN(ary)) return ST_DELETE;
|
if (!RARRAY_LEN(ary)) return ST_DELETE;
|
||||||
return ST_CONTINUE;
|
return ST_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
wmap_finalize(VALUE self, VALUE obj)
|
wmap_finalize(VALUE self, VALUE objid)
|
||||||
{
|
{
|
||||||
st_data_t key, data;
|
st_data_t orig, wmap, data;
|
||||||
VALUE rids;
|
VALUE obj, rids;
|
||||||
long i;
|
long i;
|
||||||
struct weakmap *w;
|
struct weakmap *w;
|
||||||
|
|
||||||
TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
|
TypedData_Get_Struct(self, struct weakmap, &weakmap_type, w);
|
||||||
/* Get reference from object id. */
|
/* Get reference from object id. */
|
||||||
obj = obj ^ FIXNUM_FLAG; /* unset FIXNUM_FLAG */
|
obj = objid ^ FIXNUM_FLAG; /* unset FIXNUM_FLAG */
|
||||||
|
|
||||||
/* obj is original referenced object and/or weak reference. */
|
/* obj is original referenced object and/or weak reference. */
|
||||||
key = (st_data_t)obj;
|
orig = (st_data_t)obj;
|
||||||
if (st_delete(w->obj2wmap, &key, &data)) {
|
if (st_delete(w->obj2wmap, &orig, &data)) {
|
||||||
rids = (VALUE)data;
|
rids = (VALUE)data;
|
||||||
for (i = 0; i < RARRAY_LEN(rids); ++i) {
|
for (i = 0; i < RARRAY_LEN(rids); ++i) {
|
||||||
data = (st_data_t)RARRAY_PTR(rids)[i];
|
wmap = (st_data_t)RARRAY_PTR(rids)[i];
|
||||||
st_delete(w->wmap2obj, &data, NULL);
|
st_delete(w->wmap2obj, &wmap, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
key = (st_data_t)obj;
|
wmap = (st_data_t)obj;
|
||||||
if (st_delete(w->wmap2obj, &key, &data)) {
|
if (st_delete(w->wmap2obj, &wmap, &orig)) {
|
||||||
st_update(w->obj2wmap, data, wmap_final_func, (st_data_t)obj);
|
wmap = (st_data_t)obj;
|
||||||
|
st_update(w->obj2wmap, orig, wmap_final_func, wmap);
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче