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

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
This commit is contained in:
nobu 2016-06-30 05:45:35 +00:00
parent 38d340f62e
commit 2282541898

View file

@ -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;