Optimize increasing the header_index

event_stream
Ryan Dahl 15 years ago
parent ca1e011ab3
commit 717d04ce2d

@ -969,8 +969,6 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state
case s_header_field: case s_header_field:
{ {
header_index++;
c = lowcase[(int)ch]; c = lowcase[(int)ch];
if (c) { if (c) {
@ -979,14 +977,17 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state
break; break;
case h_C: case h_C:
header_index++;
header_state = (c == 'o' ? h_CO : h_general); header_state = (c == 'o' ? h_CO : h_general);
break; break;
case h_CO: case h_CO:
header_index++;
header_state = (c == 'n' ? h_CON : h_general); header_state = (c == 'n' ? h_CON : h_general);
break; break;
case h_CON: case h_CON:
header_index++;
switch (c) { switch (c) {
case 'n': case 'n':
header_state = h_matching_connection; header_state = h_matching_connection;
@ -1003,6 +1004,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state
/* connection */ /* connection */
case h_matching_connection: case h_matching_connection:
header_index++;
if (header_index > sizeof(CONNECTION)-1 if (header_index > sizeof(CONNECTION)-1
|| c != CONNECTION[header_index]) { || c != CONNECTION[header_index]) {
header_state = h_general; header_state = h_general;
@ -1014,6 +1016,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state
/* content-length */ /* content-length */
case h_matching_content_length: case h_matching_content_length:
header_index++;
if (header_index > sizeof(CONTENT_LENGTH)-1 if (header_index > sizeof(CONTENT_LENGTH)-1
|| c != CONTENT_LENGTH[header_index]) { || c != CONTENT_LENGTH[header_index]) {
header_state = h_general; header_state = h_general;
@ -1025,6 +1028,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state
/* transfer-encoding */ /* transfer-encoding */
case h_matching_transfer_encoding: case h_matching_transfer_encoding:
header_index++;
if (header_index > sizeof(TRANSFER_ENCODING)-1 if (header_index > sizeof(TRANSFER_ENCODING)-1
|| c != TRANSFER_ENCODING[header_index]) { || c != TRANSFER_ENCODING[header_index]) {
header_state = h_general; header_state = h_general;
@ -1147,8 +1151,6 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state
break; break;
} }
header_index++;
switch (header_state) { switch (header_state) {
case h_general: case h_general:
break; break;
@ -1166,6 +1168,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state
/* Transfer-Encoding: chunked */ /* Transfer-Encoding: chunked */
case h_matching_transfer_encoding_chunked: case h_matching_transfer_encoding_chunked:
header_index++;
if (header_index > sizeof(CHUNKED)-1 if (header_index > sizeof(CHUNKED)-1
|| c != CHUNKED[header_index]) { || c != CHUNKED[header_index]) {
header_state = h_general; header_state = h_general;
@ -1176,6 +1179,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state
/* looking for 'Connection: keep-alive' */ /* looking for 'Connection: keep-alive' */
case h_matching_connection_keep_alive: case h_matching_connection_keep_alive:
header_index++;
if (header_index > sizeof(KEEP_ALIVE)-1 if (header_index > sizeof(KEEP_ALIVE)-1
|| c != KEEP_ALIVE[header_index]) { || c != KEEP_ALIVE[header_index]) {
header_state = h_general; header_state = h_general;
@ -1186,6 +1190,7 @@ size_t parse (http_parser *parser, const char *data, size_t len, int start_state
/* looking for 'Connection: close' */ /* looking for 'Connection: close' */
case h_matching_connection_close: case h_matching_connection_close:
header_index++;
if (header_index > sizeof(CLOSE)-1 || c != CLOSE[header_index]) { if (header_index > sizeof(CLOSE)-1 || c != CLOSE[header_index]) {
header_state = h_general; header_state = h_general;
} else if (header_index == sizeof(CLOSE)-2) { } else if (header_index == sizeof(CLOSE)-2) {

Loading…
Cancel
Save