summaryrefslogtreecommitdiffstats
path: root/encoding.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-07 02:49:01 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-01-07 02:49:01 +0000
commit8cecfd6b562f5805ab40bcf409e331a769d9968a (patch)
tree1fa0a156e8ce6f20d43ea627e0cb847bcb8f8982 /encoding.c
parenta61009a79b66aa5127dd4b056703fce4947fa645 (diff)
downloadruby-8cecfd6b562f5805ab40bcf409e331a769d9968a.tar.gz
ruby-8cecfd6b562f5805ab40bcf409e331a769d9968a.tar.xz
ruby-8cecfd6b562f5805ab40bcf409e331a769d9968a.zip
* encoding.c (rb_enc_internal_get_index): extracted from
rb_enc_get_index. (rb_enc_internal_set_index): extracted from rb_enc_associate_index * include/ruby/encoding.h (ENCODING_SET): work over ENCODING_INLINE_MAX. (ENCODING_GET): ditto. (ENCODING_IS_ASCII8BIT): defined. (ENCODING_CODERANGE_SET): defined. * re.c (rb_reg_fixed_encoding_p): use ENCODING_IS_ASCII8BIT. * string.c (rb_enc_str_buf_cat): use ENCODING_IS_ASCII8BIT. * parse.y (reg_fragment_setenc_gen): use ENCODING_IS_ASCII8BIT. * marshal.c (has_ivars): use ENCODING_IS_ASCII8BIT. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@14922 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'encoding.c')
-rw-r--r--encoding.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/encoding.c b/encoding.c
index 2d1813fe9..65609763a 100644
--- a/encoding.c
+++ b/encoding.c
@@ -436,6 +436,33 @@ rb_id_encoding(void)
return id_encoding;
}
+int
+rb_enc_internal_get_index(VALUE obj)
+{
+ int i;
+
+ i = ENCODING_GET_INLINED(obj);
+ if (i == ENCODING_INLINE_MAX) {
+ VALUE iv;
+
+ iv = rb_ivar_get(obj, rb_id_encoding());
+ i = NUM2INT(iv);
+ }
+ return i;
+}
+
+void
+rb_enc_internal_set_index(VALUE obj, int idx)
+{
+ if (idx < ENCODING_INLINE_MAX) {
+ ENCODING_SET_INLINED(obj, idx);
+ return;
+ }
+ ENCODING_SET_INLINED(obj, ENCODING_INLINE_MAX);
+ rb_ivar_set(obj, rb_id_encoding(), INT2NUM(idx));
+ return;
+}
+
void
rb_enc_associate_index(VALUE obj, int idx)
{
@@ -444,13 +471,7 @@ rb_enc_associate_index(VALUE obj, int idx)
!rb_enc_asciicompat(rb_enc_from_index(idx))) {
ENC_CODERANGE_CLEAR(obj);
}
- if (idx < ENCODING_INLINE_MAX) {
- ENCODING_SET(obj, idx);
- return;
- }
- ENCODING_SET(obj, ENCODING_INLINE_MAX);
- rb_ivar_set(obj, rb_id_encoding(), INT2NUM(idx));
- return;
+ rb_enc_internal_set_index(obj, idx);
}
int
@@ -476,17 +497,8 @@ rb_enc_associate(VALUE obj, rb_encoding *enc)
int
rb_enc_get_index(VALUE obj)
{
- int i;
-
if (!enc_capable(obj)) return -1;
- i = ENCODING_GET(obj);
- if (i == ENCODING_INLINE_MAX) {
- VALUE iv;
-
- iv = rb_ivar_get(obj, rb_id_encoding());
- i = NUM2INT(iv);
- }
- return i;
+ return rb_enc_internal_get_index(obj);
}
rb_encoding*