1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* string.c (str_sublen): removed.

* string.c (rb_str_reverse, rb_str_reverse_bang): use 
  single_byte_optimizable.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15583 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2008-02-23 11:18:07 +00:00
parent 386aa4c0a1
commit c1d3465081
2 changed files with 13 additions and 12 deletions

View file

@ -1,3 +1,10 @@
Sat Feb 23 20:16:05 2008 NARUSE, Yui <naruse@ruby-lang.org>
* string.c (str_sublen): removed.
* string.c (rb_str_reverse, rb_str_reverse_bang): use
single_byte_optimizable.
Sat Feb 23 19:25:18 2008 NARUSE, Yui <naruse@ruby-lang.org> Sat Feb 23 19:25:18 2008 NARUSE, Yui <naruse@ruby-lang.org>
* string.c (rb_enc_cr_str_copy_for_substr): renamed from * string.c (rb_enc_cr_str_copy_for_substr): renamed from

View file

@ -1165,23 +1165,17 @@ str_utf8_offset(const char *p, const char *e, int nth)
} }
#endif #endif
static long long
str_sublen(VALUE str, long pos, rb_encoding *enc) rb_str_sublen(VALUE str, long pos)
{ {
if (rb_enc_mbmaxlen(enc) == 1 || pos < 0) if (single_byte_optimizable(str) || pos < 0)
return pos; return pos;
else { else {
char *p = RSTRING_PTR(str); char *p = RSTRING_PTR(str);
return rb_enc_strlen(p, p + pos, enc); return rb_enc_strlen(p, p + pos, STR_ENC_GET(str));
} }
} }
int
rb_str_sublen(VALUE str, int len)
{
return str_sublen(str, len, STR_ENC_GET(str));
}
VALUE VALUE
rb_str_subseq(VALUE str, long beg, long len) rb_str_subseq(VALUE str, long beg, long len)
{ {
@ -3480,7 +3474,7 @@ rb_str_reverse(VALUE str)
p = RSTRING_END(obj); p = RSTRING_END(obj);
if (RSTRING_LEN(str) > 1) { if (RSTRING_LEN(str) > 1) {
if (rb_enc_mbmaxlen(enc) == 1) { if (single_byte_optimizable(str)) {
while (s < e) { while (s < e) {
*--p = *s++; *--p = *s++;
} }
@ -3521,7 +3515,7 @@ rb_str_reverse_bang(VALUE str)
s = RSTRING_PTR(str); s = RSTRING_PTR(str);
e = RSTRING_END(str) - 1; e = RSTRING_END(str) - 1;
if (rb_enc_mbmaxlen(enc) == 1) { if (single_byte_optimizable(str)) {
while (s < e) { while (s < e) {
c = *s; c = *s;
*s++ = *e; *s++ = *e;