[前][次][番号順一覧][スレッド一覧]

ruby-changes:72206

From: S-H-GAMELINKS <ko1@a...>
Date: Fri, 17 Jun 2022 12:03:01 +0900 (JST)
Subject: [ruby-changes:72206] 420f3ced4d (master): Using is_ascii_string to check encoding

https://git.ruby-lang.org/ruby.git/commit/?id=420f3ced4d

From 420f3ced4d25c0e81d06f3186c8cfdc509326268 Mon Sep 17 00:00:00 2001
From: S-H-GAMELINKS <gamelinks007@g...>
Date: Sun, 1 May 2022 23:13:59 +0900
Subject: Using is_ascii_string to check encoding

---
 file.c      | 2 +-
 io.c        | 2 +-
 marshal.c   | 2 +-
 parse.y     | 8 ++++----
 string.c    | 6 +++---
 transcode.c | 2 +-
 6 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/file.c b/file.c
index 007a9cb88e..e92ceeabe1 100644
--- a/file.c
+++ b/file.c
@@ -4001,7 +4001,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na https://github.com/ruby/ruby/blob/trunk/file.c#L4001
 	rb_str_set_len(result, p - buf + strlen(p));
 	encidx = ENCODING_GET(result);
 	tmp = result;
-	if (encidx != ENCINDEX_UTF_8 && rb_enc_str_coderange(result) != ENC_CODERANGE_7BIT) {
+	if (encidx != ENCINDEX_UTF_8 && !is_ascii_string(result)) {
 	    tmp = rb_str_encode_ospath(result);
 	}
 	len = MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(tmp), -1, NULL, 0);
diff --git a/io.c b/io.c
index 170ccc690a..fc1a5d8110 100644
--- a/io.c
+++ b/io.c
@@ -3836,7 +3836,7 @@ check_getline_args(VALUE *rsp, long *limit, VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L3836
 	enc_rs = rb_enc_get(rs);
 	enc_io = io_read_encoding(fptr);
 	if (enc_io != enc_rs &&
-	    (rb_enc_str_coderange(rs) != ENC_CODERANGE_7BIT ||
+	    (!is_ascii_string(rs) ||
 	     (RSTRING_LEN(rs) > 0 && !rb_enc_asciicompat(enc_io)))) {
             if (rs == rb_default_rs) {
                 rs = rb_enc_str_new(0, 0, enc_io);
diff --git a/marshal.c b/marshal.c
index c5327fca60..8267658f5c 100644
--- a/marshal.c
+++ b/marshal.c
@@ -481,7 +481,7 @@ w_symbol(VALUE sym, struct dump_arg *arg) https://github.com/ruby/ruby/blob/trunk/marshal.c#L481
 	}
 	encname = encoding_name(sym, arg);
 	if (NIL_P(encname) ||
-	    rb_enc_str_coderange(sym) == ENC_CODERANGE_7BIT) {
+	    is_ascii_string(sym)) {
 	    encname = Qnil;
 	}
 	else {
diff --git a/parse.y b/parse.y
index be5af00d43..4183804700 100644
--- a/parse.y
+++ b/parse.y
@@ -6570,7 +6570,7 @@ parser_str_new(const char *ptr, long len, rb_encoding *enc, int func, rb_encodin https://github.com/ruby/ruby/blob/trunk/parse.y#L6570
 
     str = rb_enc_str_new(ptr, len, enc);
     if (!(func & STR_FUNC_REGEXP) && rb_enc_asciicompat(enc)) {
-	if (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT) {
+	if (is_ascii_string(str)) {
 	}
 	else if (enc0 == rb_usascii_encoding() && enc != rb_utf8_encoding()) {
 	    rb_enc_associate(str, rb_ascii8bit_encoding());
@@ -12939,21 +12939,21 @@ rb_reg_fragment_setenc(struct parser_params* p, VALUE str, int options) https://github.com/ruby/ruby/blob/trunk/parse.y#L12939
 	int opt, idx;
 	rb_char_to_option_kcode(c, &opt, &idx);
 	if (idx != ENCODING_GET(str) &&
-	    rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
+	    !is_ascii_string(str)) {
             goto error;
 	}
 	ENCODING_SET(str, idx);
     }
     else if (RE_OPTION_ENCODING_NONE(options)) {
         if (!ENCODING_IS_ASCII8BIT(str) &&
-            rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
+            !is_ascii_string(str)) {
             c = 'n';
             goto error;
         }
 	rb_enc_associate(str, rb_ascii8bit_encoding());
     }
     else if (p->enc == rb_usascii_encoding()) {
-	if (rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
+	if (!is_ascii_string(str)) {
 	    /* raise in re.c */
 	    rb_enc_associate(str, rb_usascii_encoding());
 	}
diff --git a/string.c b/string.c
index e06e7745a6..23c651618d 100644
--- a/string.c
+++ b/string.c
@@ -856,7 +856,7 @@ rb_enc_str_asciionly_p(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L856
 
     if (!rb_enc_asciicompat(enc))
         return FALSE;
-    else if (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT)
+    else if (is_ascii_string(str))
         return TRUE;
     return FALSE;
 }
@@ -1276,7 +1276,7 @@ rb_external_str_with_enc(VALUE str, rb_encoding *eenc) https://github.com/ruby/ruby/blob/trunk/string.c#L1276
 {
     int eidx = rb_enc_to_index(eenc);
     if (eidx == rb_usascii_encindex() &&
-	rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) {
+	!is_ascii_string(str)) {
 	rb_enc_associate_index(str, rb_ascii8bit_encindex());
 	return str;
     }
@@ -3521,7 +3521,7 @@ st_index_t https://github.com/ruby/ruby/blob/trunk/string.c#L3521
 rb_str_hash(VALUE str)
 {
     int e = ENCODING_GET(str);
-    if (e && rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT) {
+    if (e && is_ascii_string(str)) {
 	e = 0;
     }
     return rb_memhash((const void *)RSTRING_PTR(str), RSTRING_LEN(str)) ^ e;
diff --git a/transcode.c b/transcode.c
index 7a080875d6..e6e585e901 100644
--- a/transcode.c
+++ b/transcode.c
@@ -2721,7 +2721,7 @@ str_transcode0(int argc, VALUE *argv, VALUE *self, int ecflags, VALUE ecopts) https://github.com/ruby/ruby/blob/trunk/transcode.c#L2721
             return NIL_P(arg2) ? -1 : dencidx;
         }
         if (senc && denc && rb_enc_asciicompat(senc) && rb_enc_asciicompat(denc)) {
-            if (rb_enc_str_coderange(str) == ENC_CODERANGE_7BIT) {
+            if (is_ascii_string(str)) {
                 return dencidx;
             }
         }
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]