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

ruby-changes:39197

From: nobu <ko1@a...>
Date: Fri, 17 Jul 2015 15:39:45 +0900 (JST)
Subject: [ruby-changes:39197] nobu:r51278 (trunk): encoding.h: ENC_CODERANGE_CLEAN_P

nobu	2015-07-17 15:39:29 +0900 (Fri, 17 Jul 2015)

  New Revision: 51278

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51278

  Log:
    encoding.h: ENC_CODERANGE_CLEAN_P
    
    * include/ruby/encoding.h (ENC_CODERANGE_CLEAN_P): predicate that
      tells if the coderange is clean, that is 7bit or valid, and no
      needs to scrub.
    * re.c (rb_reg_expr_str): use ENC_CODERANGE_CLEAN_P.
    * string.c (enc_strlen, rb_enc_cr_str_buf_cat, rb_str_scrub):
      ditto.
    * string.c (rb_str_enumerate_chars): ditto, and suppress a warning
      by gcc6.

  Modified files:
    trunk/ChangeLog
    trunk/include/ruby/encoding.h
    trunk/re.c
    trunk/string.c
Index: include/ruby/encoding.h
===================================================================
--- include/ruby/encoding.h	(revision 51277)
+++ include/ruby/encoding.h	(revision 51278)
@@ -49,6 +49,12 @@ RUBY_SYMBOL_EXPORT_BEGIN https://github.com/ruby/ruby/blob/trunk/include/ruby/encoding.h#L49
 #define ENC_CODERANGE_7BIT	((int)FL_USER8)
 #define ENC_CODERANGE_VALID	((int)FL_USER9)
 #define ENC_CODERANGE_BROKEN	((int)(FL_USER8|FL_USER9))
+static inline int
+rb_enc_coderange_clean_p(int cr)
+{
+    return (cr ^ (cr >> 1)) & ENC_CODERANGE_7BIT;
+}
+#define ENC_CODERANGE_CLEAN_P(cr) rb_enc_coderange_clean_p(cr)
 #define ENC_CODERANGE(obj) ((int)RBASIC(obj)->flags & ENC_CODERANGE_MASK)
 #define ENC_CODERANGE_ASCIIONLY(obj) (ENC_CODERANGE(obj) == ENC_CODERANGE_7BIT)
 #define ENC_CODERANGE_SET(obj,cr) (RBASIC(obj)->flags = \
Index: re.c
===================================================================
--- re.c	(revision 51277)
+++ re.c	(revision 51278)
@@ -340,8 +340,7 @@ rb_reg_expr_str(VALUE str, const char *s https://github.com/ruby/ruby/blob/trunk/re.c#L340
 
     p = s; pend = p + len;
     rb_str_coderange_scan_restartable(p, pend, enc, &cr);
-    if (rb_enc_asciicompat(enc) &&
-	(cr == ENC_CODERANGE_VALID || cr == ENC_CODERANGE_7BIT)) {
+    if (rb_enc_asciicompat(enc) && ENC_CODERANGE_CLEAN_P(cr)) {
 	while (p < pend) {
 	    c = rb_enc_ascget(p, pend, &clen, enc);
 	    if (c == -1) {
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51277)
+++ ChangeLog	(revision 51278)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jul 17 15:39:19 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* include/ruby/encoding.h (ENC_CODERANGE_CLEAN_P): predicate that
+	  tells if the coderange is clean, that is 7bit or valid, and no
+	  needs to scrub.
+
+	* re.c (rb_reg_expr_str): use ENC_CODERANGE_CLEAN_P.
+
+	* string.c (enc_strlen, rb_enc_cr_str_buf_cat, rb_str_scrub):
+	  ditto.
+
+	* string.c (rb_str_enumerate_chars): ditto, and suppress a warning
+	  by gcc6.
+
 Fri Jul 17 15:36:52 2015  yui-knk  <spiketeika@g...>
 
 	* test/ruby/test_range.rb (test_first_last): Add test for
Index: string.c
===================================================================
--- string.c	(revision 51277)
+++ string.c	(revision 51278)
@@ -1300,7 +1300,7 @@ enc_strlen(const char *p, const char *e, https://github.com/ruby/ruby/blob/trunk/string.c#L1300
 #endif
     else if (rb_enc_asciicompat(enc)) {
         c = 0;
-	if (cr == ENC_CODERANGE_7BIT || cr == ENC_CODERANGE_VALID) {
+	if (ENC_CODERANGE_CLEAN_P(cr)) {
 	    while (p < e) {
 		if (ISASCII(*p)) {
 		    q = search_nonascii(p, e);
@@ -2335,7 +2335,7 @@ rb_enc_cr_str_buf_cat(VALUE str, const c https://github.com/ruby/ruby/blob/trunk/string.c#L2335
     }
     else if (str_cr == ENC_CODERANGE_VALID) {
         res_encindex = str_encindex;
-	if (ptr_cr == ENC_CODERANGE_7BIT || ptr_cr == ENC_CODERANGE_VALID)
+	if (ENC_CODERANGE_CLEAN_P(ptr_cr))
 	    res_cr = str_cr;
 	else
 	    res_cr = ptr_cr;
@@ -6970,9 +6970,7 @@ rb_str_enumerate_chars(VALUE str, int wa https://github.com/ruby/ruby/blob/trunk/string.c#L6970
 	    return SIZED_ENUMERATOR(str, 0, 0, rb_str_each_char_size);
     }
 
-    switch (ENC_CODERANGE(str)) {
-      case ENC_CODERANGE_VALID:
-      case ENC_CODERANGE_7BIT:
+    if (ENC_CODERANGE_CLEAN_P(ENC_CODERANGE(str))) {
 	for (i = 0; i < len; i += n) {
 	    n = rb_enc_fast_mbclen(ptr + i, ptr + len, enc);
 	    substr = rb_str_subseq(str, i, n);
@@ -6981,8 +6979,8 @@ rb_str_enumerate_chars(VALUE str, int wa https://github.com/ruby/ruby/blob/trunk/string.c#L6979
 	    else
 		rb_yield(substr);
 	}
-	break;
-      default:
+    }
+    else {
 	for (i = 0; i < len; i += n) {
 	    n = rb_enc_mbclen(ptr + i, ptr + len, enc);
 	    substr = rb_str_subseq(str, i, n);
@@ -8377,7 +8375,7 @@ rb_str_scrub(VALUE str, VALUE repl) https://github.com/ruby/ruby/blob/trunk/string.c#L8375
     rb_encoding *enc;
     int encidx;
 
-    if (cr == ENC_CODERANGE_7BIT || cr == ENC_CODERANGE_VALID)
+    if (ENC_CODERANGE_CLEAN_P(cr))
 	return Qnil;
 
     enc = STR_ENC_GET(str);

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

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