summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hawthorn <john@hawthorn.email>2025-09-18 22:02:38 -0700
committerJohn Hawthorn <john@hawthorn.email>2025-09-19 15:35:15 -0700
commit02d5b8443a0f77bf498d29c0121e035f4deeaa27 (patch)
treea99f1b6d4e74680b3de21e5d7c6dd7045f3ec89b
parentf048f77c4a0bf9cb604e2f3291dda71978ed8313 (diff)
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.
-rw-r--r--encoding.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/encoding.c b/encoding.c
index 4ccb29d2a1..da434cda1a 100644
--- a/encoding.c
+++ b/encoding.c
@@ -837,38 +837,27 @@ enc_autoload_body(rb_encoding *enc)
GLOBAL_ENC_TABLE_LOCKING(enc_table) {
base = enc_table->list[ENC_TO_ENCINDEX(enc)].base;
- if (base) {
- do {
- if (i >= enc_table->count) {
- i = -1;
- break;
- }
- } while (enc_table->list[i].enc != base && (++i, 1));
- }
}
-
- if (i != -1) {
- if (base) {
- bool do_register = true;
- if (rb_enc_autoload_p(base)) {
- if (rb_enc_autoload(base) < 0) {
- do_register = false;
- i = -1;
- }
+ if (base) {
+ bool do_register = true;
+ if (rb_enc_autoload_p(base)) {
+ if (rb_enc_autoload(base) < 0) {
+ do_register = false;
+ i = -1;
}
+ }
- if (do_register) {
- GLOBAL_ENC_TABLE_LOCKING(enc_table) {
- i = ENC_TO_ENCINDEX(enc);
- enc_load_from_base(enc_table, i, base);
- RUBY_ASSERT(((rb_raw_encoding *)enc)->ruby_encoding_index == i);
- }
+ if (do_register) {
+ GLOBAL_ENC_TABLE_LOCKING(enc_table) {
+ i = ENC_TO_ENCINDEX(enc);
+ enc_load_from_base(enc_table, i, base);
+ RUBY_ASSERT(((rb_raw_encoding *)enc)->ruby_encoding_index == i);
}
}
- else {
- i = -2;
- }
+ }
+ else {
+ i = -2;
}
return i;