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

Explicitly initialise encodings on init to remove branches on encoding lookup

[Misc #15806]

Closes: https://github.com/ruby/ruby/pull/2128
This commit is contained in:
Lourens Naudé 2019-04-13 17:05:58 +01:00 committed by Nobuyoshi Nakada
parent c25ff7bb5d
commit 6546aed475
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 7 additions and 17 deletions

View file

@ -66,8 +66,6 @@ static struct {
#define ENC_DUMMY_P(enc) ((enc)->ruby_encoding_index & ENC_DUMMY_FLAG) #define ENC_DUMMY_P(enc) ((enc)->ruby_encoding_index & ENC_DUMMY_FLAG)
#define ENC_SET_DUMMY(enc) ((enc)->ruby_encoding_index |= ENC_DUMMY_FLAG) #define ENC_SET_DUMMY(enc) ((enc)->ruby_encoding_index |= ENC_DUMMY_FLAG)
void rb_enc_init(void);
#define ENCODING_COUNT ENCINDEX_BUILTIN_MAX #define ENCODING_COUNT ENCINDEX_BUILTIN_MAX
#define UNSPECIFIED_ENCODING INT_MAX #define UNSPECIFIED_ENCODING INT_MAX
@ -557,9 +555,6 @@ rb_enc_alias(const char *alias, const char *orig)
int idx; int idx;
enc_check_duplication(alias); enc_check_duplication(alias);
if (!enc_table.list) {
rb_enc_init();
}
if ((idx = rb_enc_find_index(orig)) < 0) { if ((idx = rb_enc_find_index(orig)) < 0) {
return -1; return -1;
} }
@ -613,9 +608,6 @@ rb_enc_init(void)
rb_encoding * rb_encoding *
rb_enc_from_index(int index) rb_enc_from_index(int index)
{ {
if (!enc_table.list) {
rb_enc_init();
}
if (index < 0 || enc_table.count <= (index &= ENC_INDEX_MASK)) { if (index < 0 || enc_table.count <= (index &= ENC_INDEX_MASK)) {
return 0; return 0;
} }
@ -1324,9 +1316,6 @@ enc_m_loader(VALUE klass, VALUE str)
rb_encoding * rb_encoding *
rb_ascii8bit_encoding(void) rb_ascii8bit_encoding(void)
{ {
if (!enc_table.list) {
rb_enc_init();
}
return enc_table.list[ENCINDEX_ASCII].enc; return enc_table.list[ENCINDEX_ASCII].enc;
} }
@ -1339,9 +1328,6 @@ rb_ascii8bit_encindex(void)
rb_encoding * rb_encoding *
rb_utf8_encoding(void) rb_utf8_encoding(void)
{ {
if (!enc_table.list) {
rb_enc_init();
}
return enc_table.list[ENCINDEX_UTF_8].enc; return enc_table.list[ENCINDEX_UTF_8].enc;
} }
@ -1354,9 +1340,6 @@ rb_utf8_encindex(void)
rb_encoding * rb_encoding *
rb_usascii_encoding(void) rb_usascii_encoding(void)
{ {
if (!enc_table.list) {
rb_enc_init();
}
return enc_table.list[ENCINDEX_US_ASCII].enc; return enc_table.list[ENCINDEX_US_ASCII].enc;
} }
@ -1933,6 +1916,12 @@ rb_enc_aliases(VALUE klass)
* *
*/ */
void
Init_encodings(void)
{
rb_enc_init();
}
void void
Init_Encoding(void) Init_Encoding(void)
{ {

View file

@ -22,6 +22,7 @@ rb_call_inits(void)
CALL(vm_postponed_job); CALL(vm_postponed_job);
CALL(Method); CALL(Method);
CALL(RandomSeedCore); CALL(RandomSeedCore);
CALL(encodings);
CALL(sym); CALL(sym);
CALL(var_tables); CALL(var_tables);
CALL(Object); CALL(Object);