summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-07 08:31:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-07 08:31:22 +0000
commit9fe491e788720e07cec6c8ec1cb385a347b64ec0 (patch)
treef33689576c0b6b58f3fc6f3884fd9cc27458b90a
parent8f4e6f14d806019471f8a6f8a3951701f5511c77 (diff)
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
-rw-r--r--ChangeLog4
-rw-r--r--string.c9
2 files changed, 13 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 70eb12bab0..15da525661 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Wed Oct 7 17:30:50 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * string.c (rb_str_times): optimize for the argument 0 and 1.
+
Wed Oct 7 01:20:46 2015 Koichi Sasada <ko1@atdot.net>
* gc.h, gc.c: introduce new debug function rb_obj_info_dump(VALUE obj)
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");