r17615 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17614‎ | r17615 | r17616 >
Date:12:55, 13 November 2006
Author:river
Status:old
Tags:
Comment:
invalid headers are unlikely
Modified paths:
  • /trunk/willow/src/include/willow.h (modified) (history)
  • /trunk/willow/src/willow/whttp_header.cc (modified) (history)

Diff [purge]

Index: trunk/willow/src/include/willow.h
@@ -82,8 +82,8 @@
8383 extern int char_table[];
8484
8585 #if defined(__GNUC__) || defined(__INTEL_COMPILER)
86 -# define likely(c) __builtin_expect((c), 1)
87 -# define unlikely(c) __builtin_expect((c), 0)
 86+# define likely(c) __builtin_expect((c), true)
 87+# define unlikely(c) __builtin_expect((c), false)
8888 #else
8989 # define likely(c) c
9090 # define unlikely(c) c
Index: trunk/willow/src/willow/whttp_header.cc
@@ -292,14 +292,14 @@
293293 size_t vlen, nlen, rnpos;
294294 while ((rn = find_rn(bufp, bufp + len)) != NULL) {
295295 for (char const *c = bufp; c < rn; ++c)
296 - if (*(unsigned char *)c > 0x7f || !*c)
 296+ if (unlikely(*(unsigned char *)c > 0x7f || !*c))
297297 return io::sink_result_error;
298298
299299 if (rn == bufp) {
300300 _sink_spigot->sp_cork();
301301 discard += bufp - buf + 2;
302302 /* request with no request is an error */
303 - if (!_got_reqtype)
 303+ if (unlikely(!_got_reqtype))
304304 return io::sink_result_error;
305305 else {
306306 if (!_is_response && _http_host.empty()) {
@@ -317,14 +317,15 @@
318318 name = bufp;
319319
320320 if (!_got_reqtype) {
321 - if ((!_is_response && parse_reqtype(bufp, rn) == -1)
322 - || (_is_response && parse_response(bufp, rn) == -1)) {
 321+ if (unlikely((!_is_response && parse_reqtype(bufp, rn) == -1)
 322+ || (_is_response && parse_response(bufp, rn) == -1))) {
323323 _sink_spigot->sp_cork();
324324 return io::sink_result_error;
325325 }
326326 _got_reqtype = true;
327327 goto next;
328328 }
 329+
329330 if (*name == ' ') {
330331 const char *s = name;
331332 /* continuation of last header */
@@ -337,7 +338,7 @@
338339 goto next;
339340 }
340341
341 - if ((value = (const char *)memchr(name, ':', rnpos)) == NULL) {
 342+ if (unlikely((value = (const char *)memchr(name, ':', rnpos)) == NULL)) {
342343 _sink_spigot->sp_cork();
343344 return io::sink_result_error;
344345 }