Use literal instead of computed value in token lookup

This commit is contained in:
Tatsuhiro Tsujikawa 2015-03-21 22:57:19 +09:00
parent ef913bc929
commit 6893608ae2
4 changed files with 23 additions and 23 deletions

View File

@ -77,7 +77,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
print '''\ print '''\
case {}:'''.format(size) case {}:'''.format(size)
print '''\ print '''\
switch (name[namelen - 1]) {''' switch (name[{}]) {{'''.format(size - 1)
for c in sorted(ents.keys()): for c in sorted(ents.keys()):
headers = sorted(ents[c]) headers = sorted(ents[c])
print '''\ print '''\

View File

@ -59,7 +59,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
print '''\ print '''\
case {}:'''.format(size) case {}:'''.format(size)
print '''\ print '''\
switch (name[namelen - 1]) {''' switch (name[{}]) {{'''.format(size - 1)
for c in sorted(ents.keys()): for c in sorted(ents.keys()):
headers = sorted(ents[c]) headers = sorted(ents[c])
print '''\ print '''\

View File

@ -76,7 +76,7 @@ typedef enum {
static int lookup_token(const uint8_t *name, size_t namelen) { static int lookup_token(const uint8_t *name, size_t namelen) {
switch (namelen) { switch (namelen) {
case 2: case 2:
switch (name[namelen - 1]) { switch (name[1]) {
case 'e': case 'e':
if (streq("t", name, 1)) { if (streq("t", name, 1)) {
return NGHTTP2_TOKEN_TE; return NGHTTP2_TOKEN_TE;
@ -85,7 +85,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 4: case 4:
switch (name[namelen - 1]) { switch (name[3]) {
case 't': case 't':
if (streq("hos", name, 3)) { if (streq("hos", name, 3)) {
return NGHTTP2_TOKEN_HOST; return NGHTTP2_TOKEN_HOST;
@ -94,7 +94,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 5: case 5:
switch (name[namelen - 1]) { switch (name[4]) {
case 'h': case 'h':
if (streq(":pat", name, 4)) { if (streq(":pat", name, 4)) {
return NGHTTP2_TOKEN__PATH; return NGHTTP2_TOKEN__PATH;
@ -103,7 +103,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 7: case 7:
switch (name[namelen - 1]) { switch (name[6]) {
case 'd': case 'd':
if (streq(":metho", name, 6)) { if (streq(":metho", name, 6)) {
return NGHTTP2_TOKEN__METHOD; return NGHTTP2_TOKEN__METHOD;
@ -125,7 +125,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 10: case 10:
switch (name[namelen - 1]) { switch (name[9]) {
case 'e': case 'e':
if (streq("keep-aliv", name, 9)) { if (streq("keep-aliv", name, 9)) {
return NGHTTP2_TOKEN_KEEP_ALIVE; return NGHTTP2_TOKEN_KEEP_ALIVE;
@ -144,7 +144,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 14: case 14:
switch (name[namelen - 1]) { switch (name[13]) {
case 'h': case 'h':
if (streq("content-lengt", name, 13)) { if (streq("content-lengt", name, 13)) {
return NGHTTP2_TOKEN_CONTENT_LENGTH; return NGHTTP2_TOKEN_CONTENT_LENGTH;
@ -153,7 +153,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 16: case 16:
switch (name[namelen - 1]) { switch (name[15]) {
case 'n': case 'n':
if (streq("proxy-connectio", name, 15)) { if (streq("proxy-connectio", name, 15)) {
return NGHTTP2_TOKEN_PROXY_CONNECTION; return NGHTTP2_TOKEN_PROXY_CONNECTION;
@ -162,7 +162,7 @@ static int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 17: case 17:
switch (name[namelen - 1]) { switch (name[16]) {
case 'g': case 'g':
if (streq("transfer-encodin", name, 16)) { if (streq("transfer-encodin", name, 16)) {
return NGHTTP2_TOKEN_TRANSFER_ENCODING; return NGHTTP2_TOKEN_TRANSFER_ENCODING;

View File

@ -403,7 +403,7 @@ int lookup_token(const std::string &name) {
int lookup_token(const uint8_t *name, size_t namelen) { int lookup_token(const uint8_t *name, size_t namelen) {
switch (namelen) { switch (namelen) {
case 2: case 2:
switch (name[namelen - 1]) { switch (name[1]) {
case 'e': case 'e':
if (util::streq_l("t", name, 1)) { if (util::streq_l("t", name, 1)) {
return HD_TE; return HD_TE;
@ -412,7 +412,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 3: case 3:
switch (name[namelen - 1]) { switch (name[2]) {
case 'a': case 'a':
if (util::streq_l("vi", name, 2)) { if (util::streq_l("vi", name, 2)) {
return HD_VIA; return HD_VIA;
@ -421,7 +421,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 4: case 4:
switch (name[namelen - 1]) { switch (name[3]) {
case 'k': case 'k':
if (util::streq_l("lin", name, 3)) { if (util::streq_l("lin", name, 3)) {
return HD_LINK; return HD_LINK;
@ -435,7 +435,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 5: case 5:
switch (name[namelen - 1]) { switch (name[4]) {
case 'h': case 'h':
if (util::streq_l(":pat", name, 4)) { if (util::streq_l(":pat", name, 4)) {
return HD__PATH; return HD__PATH;
@ -449,7 +449,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 6: case 6:
switch (name[namelen - 1]) { switch (name[5]) {
case 'e': case 'e':
if (util::streq_l("cooki", name, 5)) { if (util::streq_l("cooki", name, 5)) {
return HD_COOKIE; return HD_COOKIE;
@ -468,7 +468,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 7: case 7:
switch (name[namelen - 1]) { switch (name[6]) {
case 'c': case 'c':
if (util::streq_l("alt-sv", name, 6)) { if (util::streq_l("alt-sv", name, 6)) {
return HD_ALT_SVC; return HD_ALT_SVC;
@ -500,7 +500,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 8: case 8:
switch (name[namelen - 1]) { switch (name[7]) {
case 'n': case 'n':
if (util::streq_l("locatio", name, 7)) { if (util::streq_l("locatio", name, 7)) {
return HD_LOCATION; return HD_LOCATION;
@ -509,7 +509,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 10: case 10:
switch (name[namelen - 1]) { switch (name[9]) {
case 'e': case 'e':
if (util::streq_l("keep-aliv", name, 9)) { if (util::streq_l("keep-aliv", name, 9)) {
return HD_KEEP_ALIVE; return HD_KEEP_ALIVE;
@ -533,7 +533,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 13: case 13:
switch (name[namelen - 1]) { switch (name[12]) {
case 'l': case 'l':
if (util::streq_l("cache-contro", name, 12)) { if (util::streq_l("cache-contro", name, 12)) {
return HD_CACHE_CONTROL; return HD_CACHE_CONTROL;
@ -542,7 +542,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 14: case 14:
switch (name[namelen - 1]) { switch (name[13]) {
case 'h': case 'h':
if (util::streq_l("content-lengt", name, 13)) { if (util::streq_l("content-lengt", name, 13)) {
return HD_CONTENT_LENGTH; return HD_CONTENT_LENGTH;
@ -556,7 +556,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 15: case 15:
switch (name[namelen - 1]) { switch (name[14]) {
case 'e': case 'e':
if (util::streq_l("accept-languag", name, 14)) { if (util::streq_l("accept-languag", name, 14)) {
return HD_ACCEPT_LANGUAGE; return HD_ACCEPT_LANGUAGE;
@ -575,7 +575,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 16: case 16:
switch (name[namelen - 1]) { switch (name[15]) {
case 'n': case 'n':
if (util::streq_l("proxy-connectio", name, 15)) { if (util::streq_l("proxy-connectio", name, 15)) {
return HD_PROXY_CONNECTION; return HD_PROXY_CONNECTION;
@ -584,7 +584,7 @@ int lookup_token(const uint8_t *name, size_t namelen) {
} }
break; break;
case 17: case 17:
switch (name[namelen - 1]) { switch (name[16]) {
case 'e': case 'e':
if (util::streq_l("if-modified-sinc", name, 16)) { if (util::streq_l("if-modified-sinc", name, 16)) {
return HD_IF_MODIFIED_SINCE; return HD_IF_MODIFIED_SINCE;