From 9fe491e788720e07cec6c8ec1cb385a347b64ec0 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 7 Oct 2015 08:31:22 +0000 Subject: string.c: optimize String#times * string.c (rb_str_times): optimize for the argument 0 and 1. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52071 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'string.c') diff --git a/string.c b/string.c index 5b556679c7..a164c34492 100644 --- a/string.c +++ b/string.c @@ -1598,6 +1598,15 @@ rb_str_times(VALUE str, VALUE times) char *ptr2; int termlen; + if (times == INT2FIX(1)) { + return rb_str_dup(str); + } + if (times == INT2FIX(0)) { + str2 = str_alloc(rb_obj_class(str)); + rb_enc_copy(str2, str); + OBJ_INFECT(str2, str); + return str2; + } len = NUM2LONG(times); if (len < 0) { rb_raise(rb_eArgError, "negative argument"); -- cgit v1.2.3