]> git.proxmox.com Git - libgit2.git/commitdiff
http-parser: Do not use bitfields
authorVicent Marti <tanoku@gmail.com>
Tue, 27 Sep 2011 12:53:57 +0000 (14:53 +0200)
committerVicent Marti <tanoku@gmail.com>
Tue, 27 Sep 2011 12:59:34 +0000 (14:59 +0200)
Bitfields suck. And if you make them with non-int types, they suck
in a non-standards compliant way. Like sucking sideways or something.

This commit removes all bitfields in the `http_parser` struct, and
replaces them with the minimal type needed to contain their values. Note
that the fields in the struct have been reordered so they can be packed
with 4-byte alignment.

This saves both memory on the parser (because non-int bitfields get expanded to
4byte in most compilers anyway) and time (because the fields are now
properly aligned and the compiler doesn't need to generate bit-level ops
to access them).

deps/http-parser/http_parser.h

index 76a61f26b7926d8b09de2b9ed6644f3991b45bcc..12be0d23a1b0d1ca88c47cfa7bc21e788cde0a00 100644 (file)
@@ -201,28 +201,29 @@ enum http_errno {
 
 struct http_parser {
   /** PRIVATE **/
-  unsigned char type : 2;
-  unsigned char flags : 6; /* F_* values from 'flags' enum; semi-public */
+  uint32_t nread;
+  int64_t content_length;
+
+  unsigned char type;
+  unsigned char flags; /* F_* values from 'flags' enum; semi-public */
   unsigned char state;
   unsigned char header_state;
   unsigned char index;
 
-  uint32_t nread;
-  int64_t content_length;
-
   /** READ-ONLY **/
-  unsigned short http_major;
-  unsigned short http_minor;
-  unsigned short status_code; /* responses only */
-  unsigned char method;    /* requests only */
-  unsigned char http_errno : 7;
 
   /* 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 char upgrade : 1;
+  unsigned char upgrade;
+
+  unsigned short http_major;
+  unsigned short http_minor;
+  unsigned short status_code; /* responses only */
+  unsigned char method;    /* requests only */
+  unsigned char http_errno;
 
 #if HTTP_PARSER_DEBUG
   uint32_t error_lineno;