diff options
author | Nobuyoshi Nakada <[email protected]> | 2024-10-05 16:06:54 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2024-10-05 16:06:54 +0900 |
commit | 4b065bbe2b3e2c5ff747cb27bb1763aa040453a3 (patch) | |
tree | fd27d71292eb28c6e792afc862b36f8689c3d389 /encoding.c | |
parent | 9dbbd0181f8c5e165f474e064c6f808050011bc8 (diff) |
Move common code to `enc_compatible_latter`
Diffstat (limited to 'encoding.c')
-rw-r--r-- | encoding.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/encoding.c b/encoding.c index 222610b1d4..d4fe6ea124 100644 --- a/encoding.c +++ b/encoding.c @@ -1053,6 +1053,13 @@ rb_enc_check(VALUE str1, VALUE str2) static rb_encoding* enc_compatible_latter(VALUE str1, VALUE str2, int idx1, int idx2) { + if (idx1 < 0 || idx2 < 0) + return 0; + + if (idx1 == idx2) { + return rb_enc_from_index(idx1); + } + int isstr1, isstr2; rb_encoding *enc1 = rb_enc_from_index(idx1); rb_encoding *enc2 = rb_enc_from_index(idx2); @@ -1111,15 +1118,7 @@ enc_compatible_str(VALUE str1, VALUE str2) int idx1 = enc_get_index_str(str1); int idx2 = enc_get_index_str(str2); - if (idx1 < 0 || idx2 < 0) - return 0; - - if (idx1 == idx2) { - return rb_enc_from_index(idx1); - } - else { - return enc_compatible_latter(str1, str2, idx1, idx2); - } + return enc_compatible_latter(str1, str2, idx1, idx2); } rb_encoding* @@ -1128,13 +1127,6 @@ rb_enc_compatible(VALUE str1, VALUE str2) int idx1 = rb_enc_get_index(str1); int idx2 = rb_enc_get_index(str2); - if (idx1 < 0 || idx2 < 0) - return 0; - - if (idx1 == idx2) { - return rb_enc_from_index(idx1); - } - return enc_compatible_latter(str1, str2, idx1, idx2); } |