From 176e384bcffd9d3de5ca4b9e56781b3c2b7bdfdd Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 11 Dec 2025 15:56:38 -0800 Subject: [PATCH] Cache filesystem_encindex --- encoding.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/encoding.c b/encoding.c index be8237281b..749cbd586d 100644 --- a/encoding.c +++ b/encoding.c @@ -97,6 +97,8 @@ static rb_encoding *global_enc_ascii, *global_enc_utf_8, *global_enc_us_ascii; +static int filesystem_encindex = ENCINDEX_ASCII_8BIT; + #define GLOBAL_ENC_TABLE_LOCKING(tbl) \ for (struct enc_table *tbl = &global_enc_table, **locking = &tbl; \ locking; \ @@ -1589,12 +1591,7 @@ rb_locale_encoding(void) int rb_filesystem_encindex(void) { - int idx; - GLOBAL_ENC_TABLE_LOCKING(enc_table) { - idx = enc_registered(enc_table, "filesystem"); - } - if (idx < 0) idx = ENCINDEX_ASCII_8BIT; - return idx; + return filesystem_encindex; } rb_encoding * @@ -1646,7 +1643,9 @@ enc_set_default_encoding(struct default_encoding *def, VALUE encoding, const cha } if (def == &default_external) { - enc_alias_internal(enc_table, "filesystem", Init_enc_set_filesystem_encoding()); + int fs_idx = Init_enc_set_filesystem_encoding(); + enc_alias_internal(enc_table, "filesystem", fs_idx); + filesystem_encindex = fs_idx; } }