1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

class.c: optimization just one key

* class.c (keyword_error): use only element itself for
  optimization in the case the key has just one element.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44068 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-12-08 07:17:21 +00:00
parent 1a5bc2864d
commit 72f60a2ff1

10
class.c
View file

@ -1857,8 +1857,14 @@ NORETURN(static void keyword_error(const char *error, VALUE keys));
static void static void
keyword_error(const char *error, VALUE keys) keyword_error(const char *error, VALUE keys)
{ {
const char *msg = RARRAY_LEN(keys) == 1 ? "" : "s"; const char *msg = "";
keys = rb_ary_join(keys, rb_usascii_str_new2(", ")); if (RARRAY_LEN(keys) == 1) {
keys = RARRAY_AREF(keys, 0);
}
else {
keys = rb_ary_join(keys, rb_usascii_str_new2(", "));
msg = "s";
}
rb_raise(rb_eArgError, "%s keyword%s: %"PRIsVALUE, error, msg, keys); rb_raise(rb_eArgError, "%s keyword%s: %"PRIsVALUE, error, msg, keys);
} }