aboutsummaryrefslogtreecommitdiffstats
path: root/struct.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-28 12:36:27 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-03-28 12:36:27 +0000
commit1d223a3bdf2451701d79bf994fa7bedaf148f417 (patch)
treec939785fb5794272f8bbb6c02f6273e06914f7d1 /struct.c
parentfd8f3cb98718be52976753e4580213b6062c2949 (diff)
downloadruby-1d223a3bdf2451701d79bf994fa7bedaf148f417.tar.gz
struct.c: avoid pinning down
* struct.c (rb_struct_set, rb_struct_aref, rb_struct_aset): get rid of pinning down dynamic symbols by SYM2ID. * struct.c (rb_struct_aref_sym, rb_struct_aset_sym): use Symbol instead of ID. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45465 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'struct.c')
-rw-r--r--struct.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/struct.c b/struct.c
index 9d89134392..0afc0a9774 100644
--- a/struct.c
+++ b/struct.c
@@ -148,16 +148,19 @@ rb_struct_modify(VALUE s)
static VALUE
rb_struct_set(VALUE obj, VALUE val)
{
- VALUE members, slot;
+ VALUE members, slot, fsym;
long i, len;
ID fid = rb_frame_this_func();
members = rb_struct_members(obj);
len = RARRAY_LEN(members);
rb_struct_modify(obj);
+ fid = rb_id_attrget(fid);
+ if (!fid) not_a_member(rb_frame_this_func());
+ fsym = ID2SYM(fid);
for (i=0; i<len; i++) {
slot = RARRAY_AREF(members, i);
- if (rb_id_attrset(SYM2ID(slot)) == fid) {
+ if (slot == fsym) {
RSTRUCT_SET(obj, i, val);
return val;
}
@@ -715,17 +718,17 @@ rb_struct_init_copy(VALUE copy, VALUE s)
}
static VALUE
-rb_struct_aref_id(VALUE s, ID id)
+rb_struct_aref_sym(VALUE s, VALUE name)
{
VALUE members = rb_struct_members(s);
long i, len = RARRAY_LEN(members);
for (i=0; i<len; i++) {
- if (SYM2ID(RARRAY_AREF(members, i)) == id) {
+ if (RARRAY_AREF(members, i) == name) {
return RSTRUCT_GET(s, i);
}
}
- rb_name_error(id, "no member '%s' in struct", rb_id2name(id));
+ rb_name_error_str(name, "no member '% "PRIsVALUE"' in struct", name);
UNREACHABLE;
}
@@ -753,7 +756,7 @@ rb_struct_aref(VALUE s, VALUE idx)
long i;
if (RB_TYPE_P(idx, T_SYMBOL)) {
- return rb_struct_aref_id(s, SYM2ID(idx));
+ return rb_struct_aref_sym(s, idx);
}
else if (RB_TYPE_P(idx, T_STRING)) {
ID id = rb_check_id_without_pindown(&idx);
@@ -761,7 +764,7 @@ rb_struct_aref(VALUE s, VALUE idx)
rb_name_error_str(idx, "no member '%"PRIsVALUE"' in struct",
QUOTE(idx));
}
- return rb_struct_aref_id(s, id);
+ return rb_struct_aref_sym(s, ID2SYM(id));
}
i = NUM2LONG(idx);
@@ -776,7 +779,7 @@ rb_struct_aref(VALUE s, VALUE idx)
}
static VALUE
-rb_struct_aset_id(VALUE s, ID id, VALUE val)
+rb_struct_aset_sym(VALUE s, VALUE name, VALUE val)
{
VALUE members = rb_struct_members(s);
long i, len = RARRAY_LEN(members);
@@ -787,13 +790,13 @@ rb_struct_aset_id(VALUE s, ID id, VALUE val)
}
for (i=0; i<len; i++) {
- if (SYM2ID(RARRAY_AREF(members, i)) == id) {
+ if (RARRAY_AREF(members, i) == name) {
rb_struct_modify(s);
RSTRUCT_SET(s, i, val);
return val;
}
}
- rb_name_error(id, "no member '%s' in struct", rb_id2name(id));
+ rb_name_error_str(name, "no member '% "PRIsVALUE"' in struct", name);
UNREACHABLE;
}
@@ -823,7 +826,7 @@ rb_struct_aset(VALUE s, VALUE idx, VALUE val)
long i;
if (RB_TYPE_P(idx, T_SYMBOL)) {
- return rb_struct_aset_id(s, SYM2ID(idx), val);
+ return rb_struct_aset_sym(s, idx, val);
}
if (RB_TYPE_P(idx, T_STRING)) {
ID id = rb_check_id(&idx);
@@ -831,7 +834,7 @@ rb_struct_aset(VALUE s, VALUE idx, VALUE val)
rb_name_error_str(idx, "no member '%"PRIsVALUE"' in struct",
QUOTE(idx));
}
- return rb_struct_aset_id(s, id, val);
+ return rb_struct_aset_sym(s, ID2SYM(id), val);
}
i = NUM2LONG(idx);