Skip to content

Commit 176e384

Browse files
committed
Cache filesystem_encindex
1 parent e7a38b3 commit 176e384

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

encoding.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ static rb_encoding *global_enc_ascii,
9797
*global_enc_utf_8,
9898
*global_enc_us_ascii;
9999

100+
static int filesystem_encindex = ENCINDEX_ASCII_8BIT;
101+
100102
#define GLOBAL_ENC_TABLE_LOCKING(tbl) \
101103
for (struct enc_table *tbl = &global_enc_table, **locking = &tbl; \
102104
locking; \
@@ -1589,12 +1591,7 @@ rb_locale_encoding(void)
15891591
int
15901592
rb_filesystem_encindex(void)
15911593
{
1592-
int idx;
1593-
GLOBAL_ENC_TABLE_LOCKING(enc_table) {
1594-
idx = enc_registered(enc_table, "filesystem");
1595-
}
1596-
if (idx < 0) idx = ENCINDEX_ASCII_8BIT;
1597-
return idx;
1594+
return filesystem_encindex;
15981595
}
15991596

16001597
rb_encoding *
@@ -1646,7 +1643,9 @@ enc_set_default_encoding(struct default_encoding *def, VALUE encoding, const cha
16461643
}
16471644

16481645
if (def == &default_external) {
1649-
enc_alias_internal(enc_table, "filesystem", Init_enc_set_filesystem_encoding());
1646+
int fs_idx = Init_enc_set_filesystem_encoding();
1647+
enc_alias_internal(enc_table, "filesystem", fs_idx);
1648+
filesystem_encindex = fs_idx;
16501649
}
16511650
}
16521651

0 commit comments

Comments
 (0)