mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* string.c (coderange_scan): optimize ASCII-8BIT string.
(rb_enc_str_buf_cat): don't call coderange_scan if possible. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14915 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
35f28e6b81
commit
b2168c5a2a
2 changed files with 31 additions and 5 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon Jan 7 01:36:49 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* string.c (coderange_scan): optimize ASCII-8BIT string.
|
||||
(rb_enc_str_buf_cat): don't call coderange_scan if possible.
|
||||
|
||||
Mon Jan 7 01:05:45 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* lib/erb.rb (ERB::Revision): cut off locale dependent string in Date
|
||||
|
|
27
string.c
27
string.c
|
@ -119,6 +119,17 @@ coderange_scan(const char *p, long len, rb_encoding *enc)
|
|||
const char *e = p + len;
|
||||
int cr;
|
||||
|
||||
if (rb_enc_to_index(enc) == 0) {
|
||||
/* enc is ASCII-8BIT. ASCII-8BIT string never be broken. */
|
||||
while (p < e) {
|
||||
if (!ISASCII((unsigned char)*p)) {
|
||||
return ENC_CODERANGE_VALID;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
return ENC_CODERANGE_7BIT;
|
||||
}
|
||||
|
||||
cr = rb_enc_asciicompat(enc) ? ENC_CODERANGE_7BIT : ENC_CODERANGE_VALID;
|
||||
while (p < e) {
|
||||
int ret = rb_enc_precise_mbclen(p, e, enc);
|
||||
|
@ -1056,14 +1067,24 @@ rb_enc_str_buf_cat(VALUE str, const char *ptr, long len, rb_encoding *ptr_enc)
|
|||
int ptr_a8 = rb_enc_to_index(ptr_enc) == 0;
|
||||
|
||||
str_cr = ENC_CODERANGE(str);
|
||||
ptr_cr = coderange_scan(ptr, len, ptr_enc);
|
||||
|
||||
if (str_enc == ptr_enc) {
|
||||
if (str_cr == ENC_CODERANGE_UNKNOWN ||
|
||||
(ptr_a8 && str_cr != ENC_CODERANGE_7BIT)) {
|
||||
ptr_cr = ENC_CODERANGE_UNKNOWN;
|
||||
}
|
||||
else {
|
||||
ptr_cr = coderange_scan(ptr, len, ptr_enc);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ptr_cr = coderange_scan(ptr, len, ptr_enc);
|
||||
if (str_cr == ENC_CODERANGE_UNKNOWN) {
|
||||
if (str_a8 ? !ptr_a8
|
||||
: (str_enc != ptr_enc && ptr_cr != ENC_CODERANGE_7BIT)) {
|
||||
if (str_a8 || ptr_cr != ENC_CODERANGE_7BIT) {
|
||||
str_cr = rb_enc_str_coderange(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (str_enc != ptr_enc &&
|
||||
str_cr != ENC_CODERANGE_7BIT &&
|
||||
|
|
Loading…
Reference in a new issue