mirror of
https://github.com/ruby/ruby.git
synced 2026-08-05 11:19:10 +08:00
Atomic fast path for "locale" encoding registration
The "locale" encoding is only registered once, so we can use an atomic to avoid the full lock and hash lookup.
This commit is contained in:
parent
de5545202d
commit
d901035136
Notes:
git
2026-05-29 18:30:17 +00:00
12
encoding.c
12
encoding.c
@ -98,6 +98,7 @@ static rb_encoding *global_enc_ascii,
|
||||
*global_enc_us_ascii;
|
||||
|
||||
static int filesystem_encindex = ENCINDEX_ASCII_8BIT;
|
||||
static rb_atomic_t locale_alias_registered;
|
||||
|
||||
#define GLOBAL_ENC_TABLE_LOCKING(tbl) \
|
||||
for (struct enc_table *tbl = &global_enc_table, **locking = &tbl; \
|
||||
@ -1568,15 +1569,16 @@ rb_locale_encindex(void)
|
||||
|
||||
if (idx < 0) idx = ENCINDEX_UTF_8;
|
||||
|
||||
GLOBAL_ENC_TABLE_LOCKING(enc_table) {
|
||||
if (enc_registered(enc_table, "locale") < 0) {
|
||||
if (!RUBY_ATOMIC_LOAD(locale_alias_registered)) {
|
||||
GLOBAL_ENC_TABLE_LOCKING(enc_table) {
|
||||
if (enc_registered(enc_table, "locale") < 0) {
|
||||
# if defined _WIN32
|
||||
void Init_w32_codepage(void);
|
||||
Init_w32_codepage();
|
||||
void Init_w32_codepage(void);
|
||||
Init_w32_codepage();
|
||||
# endif
|
||||
GLOBAL_ENC_TABLE_LOCKING(enc_table) {
|
||||
enc_alias_internal(enc_table, "locale", idx);
|
||||
}
|
||||
RUBY_ATOMIC_SET(locale_alias_registered, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user