ruby-changes:27876
From: nobu <ko1@a...>
Date: Mon, 25 Mar 2013 18:13:16 +0900 (JST)
Subject: [ruby-changes:27876] nobu:r39928 (trunk): string.c: performance improvement
nobu 2013-03-25 18:13:08 +0900 (Mon, 25 Mar 2013) New Revision: 39928 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39928 Log: string.c: performance improvement * string.c (rb_str_rpartition): get rid of conversion from byte offset to char offset and backward, for performance improvement. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 39927) +++ string.c (revision 39928) @@ -7522,7 +7522,6 @@ rb_str_rpartition(VALUE str, VALUE sep) https://github.com/ruby/ruby/blob/trunk/string.c#L7522 if (RB_TYPE_P(sep, T_REGEXP)) { pos = rb_reg_search(sep, str, pos, 1); - pos = rb_str_sublen(str, pos); regex = TRUE; } else { @@ -7543,9 +7542,13 @@ rb_str_rpartition(VALUE str, VALUE sep) https://github.com/ruby/ruby/blob/trunk/string.c#L7542 if (regex) { sep = rb_reg_nth_match(0, rb_backref_get()); } - return rb_ary_new3(3, rb_str_substr(str, 0, pos), + else { + pos = rb_str_offset(str, pos); + } + return rb_ary_new3(3, rb_str_subseq(str, 0, pos), sep, - rb_str_substr(str,pos+str_strlen(sep,STR_ENC_GET(sep)),RSTRING_LEN(str))); + rb_str_subseq(str, pos+RSTRING_LEN(sep), + RSTRING_LEN(str)-pos-RSTRING_LEN(sep))); } /* -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/