Skip to content

Commit

Permalink
Use literal instead of computed value in token lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsuhiro-t committed Mar 21, 2015
1 parent ef913bc commit 6893608
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion genheaderfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def gen_index_header():
print '''\
case {}:'''.format(size)
print '''\
switch (name[namelen - 1]) {'''
switch (name[{}]) {{'''.format(size - 1)
for c in sorted(ents.keys()):
headers = sorted(ents[c])
print '''\
Expand Down
2 changes: 1 addition & 1 deletion genlibtokenlookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def gen_index_header():
print '''\
case {}:'''.format(size)
print '''\
switch (name[namelen - 1]) {'''
switch (name[{}]) {{'''.format(size - 1)
for c in sorted(ents.keys()):
headers = sorted(ents[c])
print '''\
Expand Down
16 changes: 8 additions & 8 deletions lib/nghttp2_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ typedef enum {
static int lookup_token(const uint8_t *name, size_t namelen) {
switch (namelen) {
case 2:
switch (name[namelen - 1]) {
switch (name[1]) {
case 'e':
if (streq("t", name, 1)) {
return NGHTTP2_TOKEN_TE;
Expand All @@ -85,7 +85,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 4:
switch (name[namelen - 1]) {
switch (name[3]) {
case 't':
if (streq("hos", name, 3)) {
return NGHTTP2_TOKEN_HOST;
Expand All @@ -94,7 +94,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 5:
switch (name[namelen - 1]) {
switch (name[4]) {
case 'h':
if (streq(":pat", name, 4)) {
return NGHTTP2_TOKEN__PATH;
Expand All @@ -103,7 +103,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 7:
switch (name[namelen - 1]) {
switch (name[6]) {
case 'd':
if (streq(":metho", name, 6)) {
return NGHTTP2_TOKEN__METHOD;
Expand All @@ -125,7 +125,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 10:
switch (name[namelen - 1]) {
switch (name[9]) {
case 'e':
if (streq("keep-aliv", name, 9)) {
return NGHTTP2_TOKEN_KEEP_ALIVE;
Expand All @@ -144,7 +144,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 14:
switch (name[namelen - 1]) {
switch (name[13]) {
case 'h':
if (streq("content-lengt", name, 13)) {
return NGHTTP2_TOKEN_CONTENT_LENGTH;
Expand All @@ -153,7 +153,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 16:
switch (name[namelen - 1]) {
switch (name[15]) {
case 'n':
if (streq("proxy-connectio", name, 15)) {
return NGHTTP2_TOKEN_PROXY_CONNECTION;
Expand All @@ -162,7 +162,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 17:
switch (name[namelen - 1]) {
switch (name[16]) {
case 'g':
if (streq("transfer-encodin", name, 16)) {
return NGHTTP2_TOKEN_TRANSFER_ENCODING;
Expand Down
26 changes: 13 additions & 13 deletions src/http2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ int lookup_token(const std::string &name) {
int lookup_token(const uint8_t *name, size_t namelen) {
switch (namelen) {
case 2:
switch (name[namelen - 1]) {
switch (name[1]) {
case 'e':
if (util::streq_l("t", name, 1)) {
return HD_TE;
Expand All @@ -412,7 +412,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 3:
switch (name[namelen - 1]) {
switch (name[2]) {
case 'a':
if (util::streq_l("vi", name, 2)) {
return HD_VIA;
Expand All @@ -421,7 +421,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 4:
switch (name[namelen - 1]) {
switch (name[3]) {
case 'k':
if (util::streq_l("lin", name, 3)) {
return HD_LINK;
Expand All @@ -435,7 +435,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 5:
switch (name[namelen - 1]) {
switch (name[4]) {
case 'h':
if (util::streq_l(":pat", name, 4)) {
return HD__PATH;
Expand All @@ -449,7 +449,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 6:
switch (name[namelen - 1]) {
switch (name[5]) {
case 'e':
if (util::streq_l("cooki", name, 5)) {
return HD_COOKIE;
Expand All @@ -468,7 +468,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 7:
switch (name[namelen - 1]) {
switch (name[6]) {
case 'c':
if (util::streq_l("alt-sv", name, 6)) {
return HD_ALT_SVC;
Expand Down Expand Up @@ -500,7 +500,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 8:
switch (name[namelen - 1]) {
switch (name[7]) {
case 'n':
if (util::streq_l("locatio", name, 7)) {
return HD_LOCATION;
Expand All @@ -509,7 +509,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 10:
switch (name[namelen - 1]) {
switch (name[9]) {
case 'e':
if (util::streq_l("keep-aliv", name, 9)) {
return HD_KEEP_ALIVE;
Expand All @@ -533,7 +533,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 13:
switch (name[namelen - 1]) {
switch (name[12]) {
case 'l':
if (util::streq_l("cache-contro", name, 12)) {
return HD_CACHE_CONTROL;
Expand All @@ -542,7 +542,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 14:
switch (name[namelen - 1]) {
switch (name[13]) {
case 'h':
if (util::streq_l("content-lengt", name, 13)) {
return HD_CONTENT_LENGTH;
Expand All @@ -556,7 +556,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 15:
switch (name[namelen - 1]) {
switch (name[14]) {
case 'e':
if (util::streq_l("accept-languag", name, 14)) {
return HD_ACCEPT_LANGUAGE;
Expand All @@ -575,7 +575,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 16:
switch (name[namelen - 1]) {
switch (name[15]) {
case 'n':
if (util::streq_l("proxy-connectio", name, 15)) {
return HD_PROXY_CONNECTION;
Expand All @@ -584,7 +584,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
}
break;
case 17:
switch (name[namelen - 1]) {
switch (name[16]) {
case 'e':
if (util::streq_l("if-modified-sinc", name, 16)) {
return HD_IF_MODIFIED_SINCE;
Expand Down

0 comments on commit 6893608

Please sign in to comment.