ruby-changes:31284
From: nobu <ko1@a...>
Date: Sat, 19 Oct 2013 19:59:12 +0900 (JST)
Subject: [ruby-changes:31284] nobu:r43363 (trunk): win32/file.c: code page table
nobu 2013-10-19 19:59:06 +0900 (Sat, 19 Oct 2013) New Revision: 43363 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43363 Log: win32/file.c: code page table * win32/file.c (code_page): use simple array instead of st_table. Modified files: trunk/ChangeLog trunk/win32/file.c Index: ChangeLog =================================================================== --- ChangeLog (revision 43362) +++ ChangeLog (revision 43363) @@ -1,4 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 -Sat Oct 19 19:55:37 2013 Nobuyoshi Nakada <nobu@r...> +Sat Oct 19 19:59:02 2013 Nobuyoshi Nakada <nobu@r...> + + * win32/file.c (code_page): use simple array instead of st_table. * encoding.c (rb_locale_encindex): defer initialization of win32 code page table until encoding db loaded. Index: win32/file.c =================================================================== --- win32/file.c (revision 43362) +++ win32/file.c (revision 43363) @@ -10,7 +10,10 @@ https://github.com/ruby/ruby/blob/trunk/win32/file.c#L10 #endif /* cache 'encoding name' => 'code page' into a hash */ -static st_table *rb_code_page; +static struct code_page_table { + USHORT *table; + unsigned int count; +} rb_code_page; #define IS_DIR_SEPARATOR_P(c) (c == L'\\' || c == L'/') #define IS_DIR_UNC_P(c) (IS_DIR_SEPARATOR_P(c[0]) && IS_DIR_SEPARATOR_P(c[1])) @@ -177,7 +180,16 @@ code_page_i(st_data_t name, st_data_t id https://github.com/ruby/ruby/blob/trunk/win32/file.c#L180 if (strncmp("CP", n, 2) == 0) { int code_page = atoi(n + 2); if (code_page != 0) { - st_insert((st_table *)arg, (st_data_t)idx, (st_data_t)code_page); + struct code_page_table *cp = (struct code_page_table *)arg; + unsigned int count = cp->count; + USHORT *table = cp->table; + if (count <= idx) { + unsigned int i = count; + cp->count = count = ((idx + 4) & ~31 | 28); + cp->table = table = realloc(table, count * sizeof(*table)); + while (i < count) table[i++] = INVALID_CODE_PAGE; + } + table[idx] = (USHORT)code_page; } } return ST_CONTINUE; @@ -192,7 +204,6 @@ static UINT https://github.com/ruby/ruby/blob/trunk/win32/file.c#L204 code_page(rb_encoding *enc) { int enc_idx; - st_data_t code_page_value; if (!enc) return system_code_page(); @@ -204,8 +215,8 @@ code_page(rb_encoding *enc) https://github.com/ruby/ruby/blob/trunk/win32/file.c#L215 return 1252; } - if (st_lookup(rb_code_page, enc_idx, &code_page_value)) - return (UINT)code_page_value; + if (0 <= enc_idx && (unsigned int)enc_idx < rb_code_page.count) + return rb_code_page.table[enc_idx]; return INVALID_CODE_PAGE; } @@ -377,9 +388,11 @@ rb_file_expand_path_internal(VALUE fname https://github.com/ruby/ruby/blob/trunk/win32/file.c#L388 rb_raise(rb_eArgError, "non-absolute home"); } - /* use filesystem encoding if expanding home dir */ - path_encoding = rb_filesystem_encoding(); - cp = path_cp = system_code_page(); + if (path_cp == INVALID_CODE_PAGE || rb_enc_str_asciionly_p(path)) { + /* use filesystem encoding if expanding home dir */ + path_encoding = rb_filesystem_encoding(); + cp = path_cp = system_code_page(); + } /* ignores dir since we are expanding home */ ignore_dir = 1; @@ -688,6 +701,6 @@ rb_file_load_ok(const char *path) https://github.com/ruby/ruby/blob/trunk/win32/file.c#L701 void Init_w32_codepage(void) { - rb_code_page = st_init_numtable(); - rb_enc_foreach_name(code_page_i, (st_data_t)rb_code_page); + if (rb_code_page.count) return; + rb_enc_foreach_name(code_page_i, (st_data_t)&rb_code_page); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/