[前][次][番号順一覧][スレッド一覧]

ruby-changes:29690

From: nobu <ko1@a...>
Date: Tue, 2 Jul 2013 17:22:48 +0900 (JST)
Subject: [ruby-changes:29690] nobu:r41742 (trunk): io.c: use built-in encoding indexes

nobu	2013-07-02 17:22:34 +0900 (Tue, 02 Jul 2013)

  New Revision: 41742

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41742

  Log:
    io.c: use built-in encoding indexes
    
    * internal.h: add UTF-{16,32}{BE,LE}.
    * io.c (io_strip_bom): use built-in encoding indexes in internal.h.

  Modified files:
    trunk/ChangeLog
    trunk/encoding.c
    trunk/internal.h
    trunk/io.c

Index: encoding.c
===================================================================
--- encoding.c	(revision 41741)
+++ encoding.c	(revision 41742)
@@ -559,6 +559,10 @@ rb_enc_init(void) https://github.com/ruby/ruby/blob/trunk/encoding.c#L559
 #undef ENC_REGISTER
 #ifndef NO_PRESERVED_ENCODING
 #define ENCDB_REGISTER(name, enc) enc_register_at(ENCINDEX_##enc, name, NULL)
+    ENCDB_REGISTER("UTF-16BE", UTF_16BE);
+    ENCDB_REGISTER("UTF-16LE", UTF_16LE);
+    ENCDB_REGISTER("UTF-32BE", UTF_32BE);
+    ENCDB_REGISTER("UTF-32LE", UTF_32LE);
 #undef ENCDB_REGISTER
 #endif
     enc_table.count = ENCINDEX_BUILTIN_MAX;
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41741)
+++ ChangeLog	(revision 41742)
@@ -1,4 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Tue Jul  2 17:22:25 2013  Nobuyoshi Nakada  <nobu@r...>
+Tue Jul  2 17:22:31 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* internal.h: add UTF-{16,32}{BE,LE}.
+
+	* io.c (io_strip_bom): use built-in encoding indexes in internal.h.
 
 	* internal.h (rb_{ascii8bit,utf8,usascii}_encindex): use built-in
 	  encoding indexes for optimization.
Index: io.c
===================================================================
--- io.c	(revision 41741)
+++ io.c	(revision 41742)
@@ -5319,7 +5319,7 @@ io_strip_bom(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L5319
       case INT2FIX(0xFE):
 	if (NIL_P(b2 = rb_io_getbyte(io))) break;
 	if (b2 == INT2FIX(0xFF)) {
-	    return rb_enc_find_index("UTF-16BE");
+	    return ENCINDEX_UTF_16BE;
 	}
 	rb_io_ungetbyte(io, b2);
 	break;
@@ -5330,14 +5330,14 @@ io_strip_bom(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L5330
 	    b3 = rb_io_getbyte(io);
 	    if (b3 == INT2FIX(0) && !NIL_P(b4 = rb_io_getbyte(io))) {
 		if (b4 == INT2FIX(0)) {
-		    return rb_enc_find_index("UTF-32LE");
+		    return ENCINDEX_UTF_32LE;
 		}
 		rb_io_ungetbyte(io, b4);
 		rb_io_ungetbyte(io, b3);
 	    }
 	    else {
 		rb_io_ungetbyte(io, b3);
-		return rb_enc_find_index("UTF-16LE");
+		return ENCINDEX_UTF_16LE;
 	    }
 	}
 	rb_io_ungetbyte(io, b2);
@@ -5348,7 +5348,7 @@ io_strip_bom(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L5348
 	if (b2 == INT2FIX(0) && !NIL_P(b3 = rb_io_getbyte(io))) {
 	    if (b3 == INT2FIX(0xFE) && !NIL_P(b4 = rb_io_getbyte(io))) {
 		if (b4 == INT2FIX(0xFF)) {
-		    return rb_enc_find_index("UTF-32BE");
+		    return ENCINDEX_UTF_32BE;
 		}
 		rb_io_ungetbyte(io, b4);
 	    }
Index: internal.h
===================================================================
--- internal.h	(revision 41741)
+++ internal.h	(revision 41742)
@@ -204,6 +204,10 @@ enum ruby_preserved_encindex { https://github.com/ruby/ruby/blob/trunk/internal.h#L204
 
 #ifndef NO_PRESERVED_ENCODING
     /* preserved indexes */
+    ENCINDEX_UTF_16BE,
+    ENCINDEX_UTF_16LE,
+    ENCINDEX_UTF_32BE,
+    ENCINDEX_UTF_32LE,
 #endif
 
     ENCINDEX_BUILTIN_MAX

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]