diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-07 07:48:24 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-01-07 07:48:24 +0000 |
commit | 4e4d4331cad48bddb91568daf2f325f08033f9b4 (patch) | |
tree | e349db2deba76d2997915dae73b15054c3c7dfb5 | |
parent | ead85d123f37be2f166acf9a2c0fb5e08368813e (diff) | |
download | ruby-4e4d4331cad48bddb91568daf2f325f08033f9b4.tar.gz |
* include/ruby/oniguruma.h (OnigEncodingType): new member
ruby_encoding_index to avoid linear search in rb_enc_to_index.
* include/ruby/encoding.h (rb_enc_to_index): macro defined to use
ruby_encoding_index.
* encoding.c (rb_enc_to_index): removed.
(enc_register_at): initialize ruby_encoding_index member.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14931 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | encoding.c | 17 | ||||
-rw-r--r-- | include/ruby/encoding.h | 2 | ||||
-rw-r--r-- | include/ruby/oniguruma.h | 1 |
4 files changed, 15 insertions, 16 deletions
@@ -1,3 +1,14 @@ +Mon Jan 7 15:52:10 2008 Tanaka Akira <akr@fsij.org> + + * include/ruby/oniguruma.h (OnigEncodingType): new member + ruby_encoding_index to avoid linear search in rb_enc_to_index. + + * include/ruby/encoding.h (rb_enc_to_index): macro defined to use + ruby_encoding_index. + + * encoding.c (rb_enc_to_index): removed. + (enc_register_at): initialize ruby_encoding_index member. + Mon Jan 7 16:10:35 2008 Eric Hodel <drbrain@segment7.net> * lib/rdoc/tokenstream.rb: Namespace under RDoc. diff --git a/encoding.c b/encoding.c index 65609763af..fc7fa37e24 100644 --- a/encoding.c +++ b/encoding.c @@ -67,7 +67,7 @@ enc_check_encoding(VALUE obj) RDATA(obj)->dmark != enc_mark) { return -1; } - index = rb_enc_to_index(RDATA(obj)->data); + index = rb_enc_to_index((rb_encoding*)RDATA(obj)->data); if (rb_enc_from_index(index) != RDATA(obj)->data) return -1; return index; @@ -141,6 +141,7 @@ enc_register_at(int index, const char *name, rb_encoding *encoding) *ent->enc = *encoding; encoding = ent->enc; encoding->name = name; + encoding->ruby_encoding_index = index; if (rb_cEncoding) { /* initialize encoding data */ enc_new(encoding); @@ -474,20 +475,6 @@ rb_enc_associate_index(VALUE obj, int idx) rb_enc_internal_set_index(obj, idx); } -int -rb_enc_to_index(rb_encoding *enc) -{ - int i; - - if (!enc) return 0; - for (i=0; i<enc_table_size; i++) { - if (enc_table[i].enc == enc) { - return i; - } - } - return 0; -} - void rb_enc_associate(VALUE obj, rb_encoding *enc) { diff --git a/include/ruby/encoding.h b/include/ruby/encoding.h index 3810d86b39..6536cb51ae 100644 --- a/include/ruby/encoding.h +++ b/include/ruby/encoding.h @@ -67,7 +67,7 @@ typedef OnigEncodingType rb_encoding; int rb_enc_replicate(const char *, rb_encoding *); int rb_define_dummy_encoding(const char *); int rb_enc_dummy_p(rb_encoding *); -int rb_enc_to_index(rb_encoding*); +#define rb_enc_to_index(enc) ((enc) ? ((enc)->ruby_encoding_index) : 0) int rb_enc_get_index(VALUE obj); int rb_enc_find_index(const char *name); int rb_to_encoding_index(VALUE); diff --git a/include/ruby/oniguruma.h b/include/ruby/oniguruma.h index 37305bc17c..7b11b51780 100644 --- a/include/ruby/oniguruma.h +++ b/include/ruby/oniguruma.h @@ -167,6 +167,7 @@ typedef struct OnigEncodingTypeST { OnigUChar* (*left_adjust_char_head)(const OnigUChar* start, const OnigUChar* p, struct OnigEncodingTypeST* enc); int (*is_allowed_reverse_match)(const OnigUChar* p, const OnigUChar* end, struct OnigEncodingTypeST* enc); void *auxiliary_data; + int ruby_encoding_index; } OnigEncodingType; typedef OnigEncodingType* OnigEncoding; |