Permalink
Browse files

reduce http_parser from 60 bytes to 48 bytes

This is mostly done by using sized types instead of enums, and
reordering fields to allow better packing.

I also moved the 'upgrade' field out of the PRIVATE section and into
the READ-ONLY section, as I believe that it is supposed to be
non-private.
  • Loading branch information...
1 parent 0e8ad4e commit 5502cddd3554144f3d9988bedce26451713369cb Cliff Frey committed with ry May 27, 2010
Showing with 12 additions and 12 deletions.
  1. +12 −12 http_parser.h
View
@@ -94,17 +94,10 @@ enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH };
struct http_parser {
/** PRIVATE **/
- enum http_parser_type type;
- unsigned short state;
- unsigned short header_state;
- size_t index;
-
- /* 1 = Upgrade header was present and the parser has exited because of that.
- * 0 = No upgrade header present.
- * Should be checked when http_parser_execute() returns in addition to
- * error checking.
- */
- unsigned short upgrade;
+ unsigned char type;
+ unsigned char state;
+ unsigned char header_state;
+ unsigned char index;
char flags;
@@ -122,11 +115,18 @@ struct http_parser {
/** READ-ONLY **/
unsigned short status_code; /* responses only */
- enum http_method method; /* requests only */
+ unsigned short method; /* requests only */
unsigned short http_major;
unsigned short http_minor;
char buffer[HTTP_PARSER_MAX_METHOD_LEN];
+ /* 1 = Upgrade header was present and the parser has exited because of that.
+ * 0 = No upgrade header present.
+ * Should be checked when http_parser_execute() returns in addition to
+ * error checking.
+ */
+ char upgrade;
+
/** PUBLIC **/
void *data; /* A pointer to get hook to the "connection" or "socket" object */
};

0 comments on commit 5502cdd

Please sign in to comment.