From 7afe0c92ea9f4e363429f3209567b4bc3de302db Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 27 May 2009 16:31:51 +0000 Subject: [PATCH] * marshal.c (w_encoding): more compact encoding information for US-ASCII and UTF-8. [incompatible] [experimental] * marshal.c (r_ivar): restore :E encoding information. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23597 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ marshal.c | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/ChangeLog b/ChangeLog index 9a187b7e33..cd0c300e4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,13 @@ Wed May 27 18:00:15 2009 Yukihiro Matsumoto * bignum.c (bigand_int): even less object allocation. +Wed May 27 14:29:55 2009 Yukihiro Matsumoto + + * marshal.c (w_encoding): more compact encoding information for + US-ASCII and UTF-8. [incompatible] [experimental] + + * marshal.c (r_ivar): restore :E encoding information. + Wed May 27 14:08:39 2009 Yukihiro Matsumoto * st.c (st_insert2): new function with processing new key, diff --git a/marshal.c b/marshal.c index 1d07a83882..807a0335a2 100644 --- a/marshal.c +++ b/marshal.c @@ -471,6 +471,7 @@ static int w_obj_each(ID id, VALUE value, struct dump_call_arg *arg) { if (id == rb_id_encoding()) return ST_CONTINUE; + if (id == rb_intern("E")) return ST_CONTINUE; w_symbol(id, arg->arg); w_object(value, arg->arg, arg->limit); return ST_CONTINUE; @@ -488,6 +489,19 @@ w_encoding(VALUE obj, long num, struct dump_call_arg *arg) return; } w_long(num + 1, arg->arg); + + /* special treatment for US-ASCII and UTF-8 */ + if (encidx == rb_usascii_encindex()) { + w_symbol(rb_intern("E"), arg->arg); + w_object(Qfalse, arg->arg, arg->limit); + return; + } + else if (encidx == rb_utf8_encindex()) { + w_symbol(rb_intern("E"), arg->arg); + w_object(Qtrue, arg->arg, arg->limit); + return; + } + w_symbol(rb_id_encoding(), arg->arg); do { if (!arg->arg->encodings) @@ -1152,6 +1166,11 @@ r_ivar(VALUE obj, struct load_arg *arg) int idx = rb_enc_find_index(StringValueCStr(val)); if (idx > 0) rb_enc_associate_index(obj, idx); } + if (id == rb_intern("E")) { + if (val == Qfalse) rb_enc_associate_index(obj, rb_usascii_encindex()); + else if (val == Qtrue) rb_enc_associate_index(obj, rb_utf8_encindex()); + /* bogus ignore */ + } else { rb_ivar_set(obj, id, val); }