diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-25 09:13:08 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-25 09:13:08 +0000 |
commit | 2149c313f4306925903eba207616d895a37f850c (patch) | |
tree | f2d8b91723603ea63aaf3c702e9662a02b055212 /string.c | |
parent | f4ac735476535dcc0acbfbc507009fc67ddeaffa (diff) |
string.c: performance improvement
* string.c (rb_str_rpartition): get rid of conversion from byte offset
to char offset and backward, for performance improvement.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39928 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -7522,7 +7522,6 @@ rb_str_rpartition(VALUE str, VALUE sep) 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) 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))); } /* |