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

ruby-changes:41658

From: nobu <ko1@a...>
Date: Thu, 4 Feb 2016 12:40:42 +0900 (JST)
Subject: [ruby-changes:41658] nobu:r53732 (trunk): initialize dest to 0

nobu	2016-02-04 12:40:41 +0900 (Thu, 04 Feb 2016)

  New Revision: 53732

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

  Log:
    initialize dest to 0
    
    * ext/cgi/escape/escape.c (optimized_escape_html): initialize dest
      to 0 and tell the result to be modified, instead of a separate
      flag.
    
    * ext/cgi/escape/escape.c (optimized_escape): ditto.

  Modified files:
    trunk/ext/cgi/escape/escape.c
Index: ext/cgi/escape/escape.c
===================================================================
--- ext/cgi/escape/escape.c	(revision 53731)
+++ ext/cgi/escape/escape.c	(revision 53732)
@@ -40,8 +40,8 @@ preserve_original_state(VALUE orig, VALU https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L40
 static VALUE
 optimized_escape_html(VALUE str)
 {
-    long i, len, modified = 0, beg = 0;
-    VALUE dest;
+    long i, len, beg = 0;
+    VALUE dest = 0;
     const char *cstr;
 
     len  = RSTRING_LEN(str);
@@ -54,8 +54,7 @@ optimized_escape_html(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L54
 	  case '"':
 	  case '<':
 	  case '>':
-	    if (!modified) {
-		modified = 1;
+	    if (!dest) {
 		dest = rb_str_buf_new(len);
 	    }
 
@@ -67,7 +66,7 @@ optimized_escape_html(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L66
 	}
     }
 
-    if (modified) {
+    if (dest) {
 	rb_str_cat(dest, cstr + beg, len - beg);
 	preserve_original_state(str, dest);
 	return dest;
@@ -99,8 +98,8 @@ url_unreserved_char(unsigned char c) https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L98
 static VALUE
 optimized_escape(VALUE str)
 {
-    long i, len, modified = 0, beg = 0;
-    VALUE dest;
+    long i, len, beg = 0;
+    VALUE dest = 0;
     const char *cstr;
     char buf[4] = {'%'};
 
@@ -109,8 +108,7 @@ optimized_escape(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L108
 
     for (i = 0; i < len; i++) {
 	if (!url_unreserved_char(cstr[i])) {
-	    if (!modified) {
-		modified = 1;
+	    if (!dest) {
 		dest = rb_str_buf_new(len);
 	    }
 
@@ -129,7 +127,7 @@ optimized_escape(VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/cgi/escape/escape.c#L127
 	}
     }
 
-    if (modified) {
+    if (dest) {
 	rb_str_cat(dest, cstr + beg, len - beg);
 	preserve_original_state(str, dest);
 	return dest;

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

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