From 7d1dd7cad8b8773490240a1d0f4fd20f55de7644 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 4 Feb 2016 03:40:41 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53732 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/cgi/escape/escape.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/ext/cgi/escape/escape.c b/ext/cgi/escape/escape.c index e04408bc61..629418370e 100644 --- a/ext/cgi/escape/escape.c +++ b/ext/cgi/escape/escape.c @@ -40,8 +40,8 @@ preserve_original_state(VALUE orig, VALUE dest) 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) case '"': case '<': case '>': - if (!modified) { - modified = 1; + if (!dest) { dest = rb_str_buf_new(len); } @@ -67,7 +66,7 @@ optimized_escape_html(VALUE str) } } - 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) 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) 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) } } - if (modified) { + if (dest) { rb_str_cat(dest, cstr + beg, len - beg); preserve_original_state(str, dest); return dest;