ruby-changes:46497
From: duerst <ko1@a...>
Date: Tue, 9 May 2017 20:13:50 +0900 (JST)
Subject: [ruby-changes:46497] duerst:r58618 (trunk): replace hand-written argument check by call to rb_scan_args in unicode_normalize_common
duerst 2017-05-09 20:13:45 +0900 (Tue, 09 May 2017) New Revision: 58618 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58618 Log: replace hand-written argument check by call to rb_scan_args in unicode_normalize_common In string.c, replace hand-written argument count check by call to rb_scan_args. This allows to use rb_funcallv once, rather than using rb_funcall twice. Thanks to Hanmac (Hans Mackowiak) for the idea, see https://bugs.ruby-lang.org/issues/11078#note-7. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 58617) +++ string.c (revision 58618) @@ -9592,17 +9592,14 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L9592 unicode_normalize_common(int argc, VALUE *argv, VALUE str, ID id) { static int UnicodeNormalizeRequired = 0; + VALUE argv2[2] = { str }; if (!UnicodeNormalizeRequired) { rb_require("unicode_normalize/normalize.rb"); UnicodeNormalizeRequired = 1; } - if (argc==0) - return rb_funcall(mUnicodeNormalize, id, 1, str); - else if (argc==1) - return rb_funcall(mUnicodeNormalize, id, 2, str, argv[0]); - else - rb_raise(rb_eArgError, "too many arguments to unicode normalization function"); + rb_scan_args(argc, argv, "01", &argv2[1]); + return rb_funcallv(mUnicodeNormalize, id, argc+1, argv2); } /* -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/