From 4d3677e14bf0adf8ddeabfff395831b8e032209c Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 12 Dec 2014 07:23:18 +0000 Subject: [PATCH] string.c: reduce intermediate string * string.c (rb_str_succ_bang): get rid of making intermediate string object. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/string.c b/string.c index 615bd3b4bc..9006abdfac 100644 --- a/string.c +++ b/string.c @@ -3271,6 +3271,8 @@ enc_succ_alnum_char(char *p, long len, rb_encoding *enc, char *carry) } +static VALUE str_succ(VALUE str); + /* * call-seq: * str.succ -> new_str @@ -3299,8 +3301,17 @@ enc_succ_alnum_char(char *p, long len, rb_encoding *enc, char *carry) VALUE rb_str_succ(VALUE orig) { - rb_encoding *enc; VALUE str; + str = rb_str_new_with_class(orig, RSTRING_PTR(orig), RSTRING_LEN(orig)); + rb_enc_cr_str_copy_for_substr(str, orig); + OBJ_INFECT(str, orig); + return str_succ(str); +} + +static VALUE +str_succ(VALUE str) +{ + rb_encoding *enc; char *sbeg, *s, *e, *last_alnum = 0; int c = -1; long l, slen; @@ -3308,13 +3319,10 @@ rb_str_succ(VALUE orig) long carry_pos = 0, carry_len = 1; enum neighbor_char neighbor = NEIGHBOR_FOUND; - str = rb_str_new_with_class(orig, RSTRING_PTR(orig), RSTRING_LEN(orig)); - rb_enc_cr_str_copy_for_substr(str, orig); - OBJ_INFECT(str, orig); slen = RSTRING_LEN(str); if (slen == 0) return str; - enc = STR_ENC_GET(orig); + enc = STR_ENC_GET(str); sbeg = RSTRING_PTR(str); s = e = sbeg + slen; @@ -3400,8 +3408,8 @@ rb_str_succ(VALUE orig) static VALUE rb_str_succ_bang(VALUE str) { - rb_str_shared_replace(str, rb_str_succ(str)); - + rb_str_modify(str); + str_succ(str); return str; }