summaryrefslogtreecommitdiff
path: root/ext/cgi
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-04 03:40:41 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-04 03:40:41 +0000
commit7d1dd7cad8b8773490240a1d0f4fd20f55de7644 (patch)
treeb375164d4c5c32407ad050a2ffd269db13e7d5c7 /ext/cgi
parent217ad664ab8a7a9b9a3a5a4aed2e90f88dc06b13 (diff)
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
Diffstat (limited to 'ext/cgi')
-rw-r--r--ext/cgi/escape/escape.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/ext/cgi/escape/escape.c b/ext/cgi/escape/escape.c
index e04408b..6294183 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;