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

ruby-changes:38794

From: nobu <ko1@a...>
Date: Sat, 13 Jun 2015 21:30:50 +0900 (JST)
Subject: [ruby-changes:38794] nobu:r50875 (trunk): io.c: simplify rb_io_modestr_fmode

nobu	2015-06-13 21:30:35 +0900 (Sat, 13 Jun 2015)

  New Revision: 50875

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

  Log:
    io.c: simplify rb_io_modestr_fmode
    
    * io.c (io_encname_bom_p): needs len always.
    
    * io.c (rb_io_modestr_fmode): check BOM only after a colon.

  Modified files:
    trunk/io.c
Index: io.c
===================================================================
--- io.c	(revision 50874)
+++ io.c	(revision 50875)
@@ -4893,10 +4893,6 @@ io_encname_bom_p(const char *name, long https://github.com/ruby/ruby/blob/trunk/io.c#L4893
 {
     static const char bom_prefix[] = "bom|utf-";
     enum {bom_prefix_len = (int)sizeof(bom_prefix) - 1};
-    if (!len) {
-	const char *p = strchr(name, ':');
-	len = p ? (long)(p - name) : (long)strlen(name);
-    }
     return len > bom_prefix_len && STRNCASECMP(name, bom_prefix, bom_prefix_len) == 0;
 }
 
@@ -4935,7 +4931,9 @@ rb_io_modestr_fmode(const char *modestr) https://github.com/ruby/ruby/blob/trunk/io.c#L4931
 	  default:
             goto error;
 	  case ':':
-	    p = m;
+	    p = strchr(m, ':');
+	    if (io_encname_bom_p(m, p ? (long)(p - m) : (long)strlen(m)))
+		fmode |= FMODE_SETENC_BY_BOM;
             goto finished;
         }
     }
@@ -4943,8 +4941,6 @@ rb_io_modestr_fmode(const char *modestr) https://github.com/ruby/ruby/blob/trunk/io.c#L4941
   finished:
     if ((fmode & FMODE_BINMODE) && (fmode & FMODE_TEXTMODE))
         goto error;
-    if (p && io_encname_bom_p(p, 0))
-	fmode |= FMODE_SETENC_BY_BOM;
 
     return fmode;
 }

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

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