aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-28 09:07:02 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-09-28 09:07:02 +0000
commit335fe1ee7bf51534c5f2abd0f359e86721307335 (patch)
tree717e24f272ff338461bfe0e684a50ec5106e5f71 /string.c
parent07d12a2a5f99ed6446f86aeb6e13e6c906a238be (diff)
downloadruby-335fe1ee7bf51534c5f2abd0f359e86721307335.tar.gz
* string.c (rb_str_comparable): need not to check asciicompat here.
* encoding.c (rb_enc_check): ditto. * string.c (rb_enc_str_coderange): tuned a bit; no broken check. * encoding.c (rb_enc_check): new encoding comparison criteria. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13547 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/string.c b/string.c
index 3f09196093..ab48a66bb6 100644
--- a/string.c
+++ b/string.c
@@ -99,26 +99,32 @@ VALUE rb_fs;
int
rb_enc_str_coderange(VALUE str)
{
- long i;
int cr = ENC_CODERANGE(str);
if (cr == ENC_CODERANGE_UNKNOWN) {
- cr = ENC_CODERANGE_SINGLE;
- for (i = 0; i < RSTRING_LEN(str); ++i) {
- const char *p = &RSTRING_PTR(str)[i];
- int c = (unsigned char)*p;
-
- if (!ISASCII(c)) {
- c = rb_enc_codepoint(p, RSTRING_END(str), rb_enc_get(str));
- if (c == -1) {
- cr = ENC_CODERANGE_BROKEN;
- }
- else {
+ rb_encoding *enc = rb_enc_get(str);
+
+ if (!rb_enc_asciicompat(enc)) {
+ cr = ENC_CODERANGE_MULTI;
+ ENC_CODERANGE_SET(str, cr);
+ return cr;
+ }
+ else {
+ const char *p = RSTRING_PTR(str);
+ const char *e = p + RSTRING_LEN(str);
+
+ cr = ENC_CODERANGE_SINGLE;
+ while (p < e) {
+ int c = (unsigned char)*p;
+
+ if (c > 0x80) {
cr = ENC_CODERANGE_MULTI;
+ break;
}
+ p++;
}
+ ENC_CODERANGE_SET(str, cr);
}
- ENC_CODERANGE_SET(str, cr);
}
return cr;
}
@@ -1169,8 +1175,7 @@ rb_str_hash(VALUE str)
if (e && is_ascii_string(str)) {
e = 0;
}
- return hash((const void *)RSTRING_PTR(str), RSTRING_LEN(str),
- e);
+ return hash((const void *)RSTRING_PTR(str), RSTRING_LEN(str), e);
}
/*
@@ -1196,8 +1201,6 @@ rb_str_comparable(VALUE str1, VALUE str2)
int idx2 = rb_enc_get_index(str2);
if (idx1 == idx2) return Qtrue;
- if (!rb_enc_asciicompat(rb_enc_from_index(idx1))) return Qfalse;
- if (!rb_enc_asciicompat(rb_enc_from_index(idx2))) return Qfalse;
if (!is_ascii_string(str1)) return Qfalse;
if (!is_ascii_string(str2)) return Qfalse;
return Qtrue;
@@ -1263,7 +1266,6 @@ rb_str_eql(VALUE str1, VALUE str2)
return Qfalse;
if (!rb_str_comparable(str1, str2)) return Qfalse;
-
if (memcmp(RSTRING_PTR(str1), RSTRING_PTR(str2),
lesser(RSTRING_LEN(str1), RSTRING_LEN(str2))) == 0)
return Qtrue;