summaryrefslogtreecommitdiff
path: root/ext/cgi
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-30 05:45:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-30 05:45:35 +0000
commit22825418985b7e481a42476b383da404cb13c94f (patch)
tree3794d9851ef1275b10cb2f8ce9dbf5374707aa7c /ext/cgi
parent38d340f62e8a103ff4b9d7b272ba65e527cca7c2 (diff)
Magic numbers
* ext/cgi/escape/escape.c (optimized_unescape_html): remove magic numbers for literal lengths. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55542 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 f11a72c..7289f43 100644
--- a/ext/cgi/escape/escape.c
+++ b/ext/cgi/escape/escape.c
@@ -105,40 +105,38 @@ optimized_unescape_html(VALUE str)
plen = i - beg;
if (++i >= len) break;
c = (unsigned char)cstr[i];
+#define MATCH(s) (len - i >= (int)rb_strlen_lit(s) && \
+ memcmp(&cstr[i], s, rb_strlen_lit(s)) == 0 && \
+ (i += rb_strlen_lit(s) - 1, 1))
switch (c) {
case 'a':
++i;
- if (len - i >= 4 && memcmp(&cstr[i], "pos;", 4) == 0) {
+ if (MATCH("pos;")) {
c = '\'';
- i += 3;
}
- else if (len - i >= 3 && memcmp(&cstr[i], "mp;", 3) == 0) {
+ else if (MATCH("mp;")) {
c = '&';
- i += 2;
}
else continue;
break;
case 'q':
++i;
- if (len - i >= 4 && memcmp(&cstr[i], "uot;", 4) == 0) {
+ if (MATCH("uot;")) {
c = '"';
- i += 3;
}
else continue;
break;
case 'g':
++i;
- if (len - i >= 2 && memcmp(&cstr[i], "t;", 2) == 0) {
+ if (MATCH("t;")) {
c = '>';
- i += 1;
}
else continue;
break;
case 'l':
++i;
- if (len - i >= 2 && memcmp(&cstr[i], "t;", 2) == 0) {
+ if (MATCH("t;")) {
c = '<';
- i += 1;
}
else continue;
break;