From ae13ab24669e787a73a98a533d4bd7db8c4b49ab Mon Sep 17 00:00:00 2001 From: naruse Date: Mon, 8 Apr 2013 03:05:15 +0000 Subject: * object.c (rb_obj_ivar_set): call to_str for string only once. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- object.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'object.c') diff --git a/object.c b/object.c index e2da8d5092..7c149b02b1 100644 --- a/object.c +++ b/object.c @@ -2189,12 +2189,16 @@ rb_obj_ivar_set(VALUE obj, VALUE iv, VALUE val) QUOTE_ID(id)); } } - else if (!rb_is_instance_name(iv)) { + else { + VALUE name = rb_check_string_type(iv); + if (NIL_P(name)) { + rb_raise(rb_eTypeError, "%+"PRIsVALUE" is not a symbol or string", iv); + } + if (!rb_is_instance_name(name)) { rb_name_error_str(iv, "`%"PRIsVALUE"' is not allowed as an instance variable name", QUOTE(iv)); - } - else { - id = rb_to_id(iv); + } + id = rb_to_id(name); } return rb_ivar_set(obj, id, val); } -- cgit v1.2.3