1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2016-02-04 03:40:41 +00:00
parent 217ad664ab
commit 7d1dd7cad8

View file

@ -40,8 +40,8 @@ preserve_original_state(VALUE orig, VALUE dest)
static VALUE static VALUE
optimized_escape_html(VALUE str) optimized_escape_html(VALUE str)
{ {
long i, len, modified = 0, beg = 0; long i, len, beg = 0;
VALUE dest; VALUE dest = 0;
const char *cstr; const char *cstr;
len = RSTRING_LEN(str); len = RSTRING_LEN(str);
@ -54,8 +54,7 @@ optimized_escape_html(VALUE str)
case '"': case '"':
case '<': case '<':
case '>': case '>':
if (!modified) { if (!dest) {
modified = 1;
dest = rb_str_buf_new(len); 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); rb_str_cat(dest, cstr + beg, len - beg);
preserve_original_state(str, dest); preserve_original_state(str, dest);
return dest; return dest;
@ -99,8 +98,8 @@ url_unreserved_char(unsigned char c)
static VALUE static VALUE
optimized_escape(VALUE str) optimized_escape(VALUE str)
{ {
long i, len, modified = 0, beg = 0; long i, len, beg = 0;
VALUE dest; VALUE dest = 0;
const char *cstr; const char *cstr;
char buf[4] = {'%'}; char buf[4] = {'%'};
@ -109,8 +108,7 @@ optimized_escape(VALUE str)
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (!url_unreserved_char(cstr[i])) { if (!url_unreserved_char(cstr[i])) {
if (!modified) { if (!dest) {
modified = 1;
dest = rb_str_buf_new(len); 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); rb_str_cat(dest, cstr + beg, len - beg);
preserve_original_state(str, dest); preserve_original_state(str, dest);
return dest; return dest;