Skip to content

Commit 4b065bb

Browse files
committed
Move common code to enc_compatible_latter
1 parent 9dbbd01 commit 4b065bb

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

encoding.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,13 @@ rb_enc_check(VALUE str1, VALUE str2)
10531053
static rb_encoding*
10541054
enc_compatible_latter(VALUE str1, VALUE str2, int idx1, int idx2)
10551055
{
1056+
if (idx1 < 0 || idx2 < 0)
1057+
return 0;
1058+
1059+
if (idx1 == idx2) {
1060+
return rb_enc_from_index(idx1);
1061+
}
1062+
10561063
int isstr1, isstr2;
10571064
rb_encoding *enc1 = rb_enc_from_index(idx1);
10581065
rb_encoding *enc2 = rb_enc_from_index(idx2);
@@ -1111,15 +1118,7 @@ enc_compatible_str(VALUE str1, VALUE str2)
11111118
int idx1 = enc_get_index_str(str1);
11121119
int idx2 = enc_get_index_str(str2);
11131120

1114-
if (idx1 < 0 || idx2 < 0)
1115-
return 0;
1116-
1117-
if (idx1 == idx2) {
1118-
return rb_enc_from_index(idx1);
1119-
}
1120-
else {
1121-
return enc_compatible_latter(str1, str2, idx1, idx2);
1122-
}
1121+
return enc_compatible_latter(str1, str2, idx1, idx2);
11231122
}
11241123

11251124
rb_encoding*
@@ -1128,13 +1127,6 @@ rb_enc_compatible(VALUE str1, VALUE str2)
11281127
int idx1 = rb_enc_get_index(str1);
11291128
int idx2 = rb_enc_get_index(str2);
11301129

1131-
if (idx1 < 0 || idx2 < 0)
1132-
return 0;
1133-
1134-
if (idx1 == idx2) {
1135-
return rb_enc_from_index(idx1);
1136-
}
1137-
11381130
return enc_compatible_latter(str1, str2, idx1, idx2);
11391131
}
11401132

0 commit comments

Comments
 (0)