Skip to content

Commit 02d5b84

Browse files
committed
Simplify enc_autoload_body
Previously we were looping over the enc_table, but when I added an assertion the only thing that loop was doing is the equivalent of ENC_TO_ENCINDEX(base). However we don't even need the index of base. Instead we should be able to just use the badirectly.
1 parent f048f77 commit 02d5b84

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

encoding.c

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -837,38 +837,27 @@ enc_autoload_body(rb_encoding *enc)
837837

838838
GLOBAL_ENC_TABLE_LOCKING(enc_table) {
839839
base = enc_table->list[ENC_TO_ENCINDEX(enc)].base;
840-
if (base) {
841-
do {
842-
if (i >= enc_table->count) {
843-
i = -1;
844-
break;
845-
}
846-
} while (enc_table->list[i].enc != base && (++i, 1));
847-
}
848840
}
849841

850-
851-
if (i != -1) {
852-
if (base) {
853-
bool do_register = true;
854-
if (rb_enc_autoload_p(base)) {
855-
if (rb_enc_autoload(base) < 0) {
856-
do_register = false;
857-
i = -1;
858-
}
842+
if (base) {
843+
bool do_register = true;
844+
if (rb_enc_autoload_p(base)) {
845+
if (rb_enc_autoload(base) < 0) {
846+
do_register = false;
847+
i = -1;
859848
}
849+
}
860850

861-
if (do_register) {
862-
GLOBAL_ENC_TABLE_LOCKING(enc_table) {
863-
i = ENC_TO_ENCINDEX(enc);
864-
enc_load_from_base(enc_table, i, base);
865-
RUBY_ASSERT(((rb_raw_encoding *)enc)->ruby_encoding_index == i);
866-
}
851+
if (do_register) {
852+
GLOBAL_ENC_TABLE_LOCKING(enc_table) {
853+
i = ENC_TO_ENCINDEX(enc);
854+
enc_load_from_base(enc_table, i, base);
855+
RUBY_ASSERT(((rb_raw_encoding *)enc)->ruby_encoding_index == i);
867856
}
868857
}
869-
else {
870-
i = -2;
871-
}
858+
}
859+
else {
860+
i = -2;
872861
}
873862

874863
return i;

0 commit comments

Comments
 (0)