summaryrefslogtreecommitdiff
path: root/win32/file.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-07 07:20:59 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-07 07:20:59 +0000
commit6531e12e0beaf5e730592d7cd1bb9eab96140433 (patch)
tree790de3603a91a1c47920c5fba56fc81ab383ada6 /win32/file.c
parent98e4a412e468b9c674e2722bf5907470ba54c60c (diff)
win32/file.c: make mapping at initialization
* win32/file.c (code_page_i, rb_w32_init_file): make encoding to code page mapping at initialization directly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'win32/file.c')
-rw-r--r--win32/file.c49
1 files changed, 20 insertions, 29 deletions
diff --git a/win32/file.c b/win32/file.c
index 065555a73f0..2122ae13598 100644
--- a/win32/file.c
+++ b/win32/file.c
@@ -168,6 +168,21 @@ system_code_page(void)
return AreFileApisANSI() ? CP_ACP : CP_OEMCP;
}
+void rb_enc_foreach_name(int (*func)(st_data_t name, st_data_t idx, st_data_t arg), st_data_t arg);
+
+static int
+code_page_i(st_data_t name, st_data_t idx, st_data_t arg)
+{
+ const char *n = (const char *)name;
+ 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);
+ }
+ }
+ return ST_CONTINUE;
+}
+
/*
Return code page number of the encoding.
Cache code page into a hash for performance since finding the code page in
@@ -178,9 +193,6 @@ code_page(rb_encoding *enc)
{
int enc_idx;
st_data_t code_page_value;
- VALUE encoding, names_ary = Qundef, name;
- ID names;
- long i;
if (!enc)
return system_code_page();
@@ -192,33 +204,10 @@ code_page(rb_encoding *enc)
return 1252;
}
- if (rb_code_page) {
- if (st_lookup(rb_code_page, enc_idx, &code_page_value))
- return (UINT)code_page_value;
- }
- else {
- rb_code_page = st_init_numtable();
- }
-
- code_page_value = INVALID_CODE_PAGE;
- encoding = rb_enc_from_encoding(enc);
- if (!NIL_P(encoding)) {
- CONST_ID(names, "names");
- names_ary = rb_funcall(encoding, names, 0);
- for (i = 0; i < RARRAY_LEN(names_ary); i++) {
- name = RARRAY_PTR(names_ary)[i];
- if (strncmp("CP", RSTRING_PTR(name), 2) == 0) {
- int code_page = atoi(RSTRING_PTR(name) + 2);
- if (code_page != 0) {
- code_page_value = code_page;
- break;
- }
- }
- }
- }
+ if (st_lookup(rb_code_page, enc_idx, &code_page_value))
+ return (UINT)code_page_value;
- st_insert(rb_code_page, enc_idx, code_page_value);
- return (UINT)code_page_value;
+ return INVALID_CODE_PAGE;
}
#define fix_string_encoding(str, encoding) rb_str_conv_enc((str), (encoding), rb_utf8_encoding())
@@ -697,4 +686,6 @@ rb_file_load_ok(const char *path)
void
rb_w32_init_file(void)
{
+ rb_code_page = st_init_numtable();
+ rb_enc_foreach_name(code_page_i, (st_data_t)rb_code_page);
}