ruby-changes:39784
From: nobu <ko1@a...>
Date: Tue, 15 Sep 2015 15:06:24 +0900 (JST)
Subject: [ruby-changes:39784] nobu:r51865 (trunk): dir.c: fundamental_encoding_p
nobu 2015-09-15 15:06:19 +0900 (Tue, 15 Sep 2015) New Revision: 51865 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51865 Log: dir.c: fundamental_encoding_p * dir.c (fundamental_encoding_p, push_glob): compare by encoding index immediately. Modified files: trunk/ChangeLog trunk/common.mk trunk/dir.c Index: ChangeLog =================================================================== --- ChangeLog (revision 51864) +++ ChangeLog (revision 51865) @@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Tue Sep 15 14:49:43 2015 Nobuyoshi Nakada <nobu@r...> +Tue Sep 15 15:06:16 2015 Nobuyoshi Nakada <nobu@r...> + + * dir.c (fundamental_encoding_p, push_glob): compare by encoding + index immediately. * enc/{ascii,us_ascii,utf_8}.c: set encoding indexes of fundamental built-in encodings so that usable as well as Index: common.mk =================================================================== --- common.mk (revision 51864) +++ common.mk (revision 51865) @@ -1246,6 +1246,7 @@ dir.$(OBJEXT): $(top_srcdir)/include/rub https://github.com/ruby/ruby/blob/trunk/common.mk#L1246 dir.$(OBJEXT): {$(VPATH)}config.h dir.$(OBJEXT): {$(VPATH)}defines.h dir.$(OBJEXT): {$(VPATH)}dir.c +dir.$(OBJEXT): {$(VPATH)}encindex.h dir.$(OBJEXT): {$(VPATH)}encoding.h dir.$(OBJEXT): {$(VPATH)}intern.h dir.$(OBJEXT): {$(VPATH)}internal.h Index: dir.c =================================================================== --- dir.c (revision 51864) +++ dir.c (revision 51865) @@ -12,6 +12,7 @@ https://github.com/ruby/ruby/blob/trunk/dir.c#L12 **********************************************************************/ #include "internal.h" +#include "encindex.h" #include <sys/types.h> #include <sys/stat.h> @@ -670,6 +671,18 @@ dir_path(VALUE dir) https://github.com/ruby/ruby/blob/trunk/dir.c#L671 } #if defined _WIN32 +static int +fundamental_encoding_p(rb_encoding *enc) +{ + switch (rb_enc_to_index(enc)) { + case ENCINDEX_ASCII: + case ENCINDEX_US_ASCII: + case ENCINDEX_UTF_8: + return TRUE; + default: + return FALSE; + } +} # define READDIR(dir, enc) rb_w32_readdir((dir), (enc)) #else # define READDIR(dir, enc) readdir((dir)) @@ -1212,9 +1225,7 @@ do_opendir(const char *path, int flags, https://github.com/ruby/ruby/blob/trunk/dir.c#L1225 DIR *dirp; #ifdef _WIN32 VALUE tmp = 0; - if (enc != rb_usascii_encoding() && - enc != rb_ascii8bit_encoding() && - enc != rb_utf8_encoding()) { + if (!fundamental_encoding_p(enc)) { tmp = rb_enc_str_new(path, strlen(path), enc); tmp = rb_str_encode_ospath(tmp); path = RSTRING_PTR(tmp); @@ -1525,10 +1536,7 @@ replace_real_basename(char *path, long b https://github.com/ruby/ruby/blob/trunk/dir.c#L1536 HANDLE h = INVALID_HANDLE_VALUE; long wlen; int e = 0; - if (enc && - enc != rb_usascii_encoding() && - enc != rb_ascii8bit_encoding() && - enc != rb_utf8_encoding()) { + if (!fundamental_encoding_p(enc)) { tmp = rb_enc_str_new_cstr(plainname, enc); tmp = rb_str_encode_ospath(tmp); plainname = RSTRING_PTR(tmp); @@ -2119,8 +2127,10 @@ push_glob(VALUE ary, VALUE str, int flag https://github.com/ruby/ruby/blob/trunk/dir.c#L2127 #ifdef __APPLE__ str = rb_str_encode_ospath(str); #endif - if (enc == rb_usascii_encoding()) enc = rb_filesystem_encoding(); - if (enc == rb_usascii_encoding()) enc = rb_ascii8bit_encoding(); + if (rb_enc_to_index(enc) == ENCINDEX_US_ASCII) + enc = rb_filesystem_encoding(); + if (rb_enc_to_index(enc) == ENCINDEX_US_ASCII) + enc = rb_ascii8bit_encoding(); flags |= GLOB_VERBOSE; args.glob.func = push_pattern; args.glob.value = ary; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/