mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (str_utf8_nth): no count_utf8_lead_bytes_with_word
optimization for short string. [ruby-core:26787] * string.c (str_utf8_offset): str_utf8_nth never return NULL. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4e073fbb93
commit
612b74343e
2 changed files with 8 additions and 3 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Wed Nov 18 10:17:09 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (str_utf8_nth): no count_utf8_lead_bytes_with_word
|
||||||
|
optimization for short string. [ruby-core:26787]
|
||||||
|
|
||||||
|
* string.c (str_utf8_offset): str_utf8_nth never return NULL.
|
||||||
|
|
||||||
Wed Nov 18 10:12:34 2009 Shugo Maeda <shugo@ruby-lang.org>
|
Wed Nov 18 10:12:34 2009 Shugo Maeda <shugo@ruby-lang.org>
|
||||||
|
|
||||||
* vm_method.c (rb_undef): should raise TypeError if klass is nil.
|
* vm_method.c (rb_undef): should raise TypeError if klass is nil.
|
||||||
|
|
4
string.c
4
string.c
|
@ -1468,7 +1468,7 @@ rb_str_offset(VALUE str, long pos)
|
||||||
static char *
|
static char *
|
||||||
str_utf8_nth(const char *p, const char *e, long nth)
|
str_utf8_nth(const char *p, const char *e, long nth)
|
||||||
{
|
{
|
||||||
if ((int)SIZEOF_VALUE * 2 < nth) {
|
if ((int)SIZEOF_VALUE < e - p && (int)SIZEOF_VALUE * 2 < nth) {
|
||||||
const VALUE *s, *t;
|
const VALUE *s, *t;
|
||||||
const VALUE lowbits = sizeof(VALUE) - 1;
|
const VALUE lowbits = sizeof(VALUE) - 1;
|
||||||
s = (const VALUE*)(~lowbits & ((VALUE)p + lowbits));
|
s = (const VALUE*)(~lowbits & ((VALUE)p + lowbits));
|
||||||
|
@ -1483,7 +1483,6 @@ str_utf8_nth(const char *p, const char *e, long nth)
|
||||||
} while (s < t && (int)sizeof(VALUE) <= nth);
|
} while (s < t && (int)sizeof(VALUE) <= nth);
|
||||||
p = (char *)s;
|
p = (char *)s;
|
||||||
}
|
}
|
||||||
if (p > e) return 0;
|
|
||||||
while (p < e) {
|
while (p < e) {
|
||||||
if (is_utf8_lead_byte(*p)) {
|
if (is_utf8_lead_byte(*p)) {
|
||||||
if (nth == 0) break;
|
if (nth == 0) break;
|
||||||
|
@ -1498,7 +1497,6 @@ static long
|
||||||
str_utf8_offset(const char *p, const char *e, long nth)
|
str_utf8_offset(const char *p, const char *e, long nth)
|
||||||
{
|
{
|
||||||
const char *pp = str_utf8_nth(p, e, nth);
|
const char *pp = str_utf8_nth(p, e, nth);
|
||||||
if (!pp) return e - p;
|
|
||||||
return pp - p;
|
return pp - p;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue