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

win32/file.c: code page table

* win32/file.c (code_page): use simple array instead of st_table.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43363 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-10-19 10:59:06 +00:00
parent eeb3156eca
commit cb4b55d3d8
2 changed files with 26 additions and 11 deletions

View file

@ -1,4 +1,6 @@
Sat Oct 19 19:55:37 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
Sat Oct 19 19:59:02 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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.

View file

@ -10,7 +10,10 @@
#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 idx, st_data_t arg)
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
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)
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, VALUE dname, int abs_mode, int long_na
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)
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);
}