1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

dir.c: fundamental_encoding_p

* dir.c (fundamental_encoding_p, push_glob): compare by encoding
  index immediately.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51865 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-09-15 06:06:19 +00:00
parent 9c9d555e7f
commit 2046f38aa6
3 changed files with 24 additions and 10 deletions

View file

@ -1,4 +1,7 @@
Tue Sep 15 14:49:43 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
Tue Sep 15 15:06:16 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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

View file

@ -1246,6 +1246,7 @@ dir.$(OBJEXT): $(top_srcdir)/include/ruby.h
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

28
dir.c
View file

@ -12,6 +12,7 @@
**********************************************************************/
#include "internal.h"
#include "encindex.h"
#include <sys/types.h>
#include <sys/stat.h>
@ -670,6 +671,18 @@ dir_path(VALUE dir)
}
#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, rb_encoding *enc)
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 base, rb_encoding *enc, int norm_p, int f
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 flags)
#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;