10000 proxy: remove endlen from parser struct · memcached/memcached@6c46dea · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c46dea

Browse files
committed
proxy: remove endlen from parser struct
not needed. reduce struct size 4 bytes.
1 parent 2982697 commit 6c46dea

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

proto_proxy.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,7 @@ static void proxy_process_command(conn *c, char *command, size_t cmdlen, bool mu
10471047
const char *curkey = pr.request + keyoff;
10481048
int klen = pr.klen;
10491049
int cmd_prefix_len = pr.tok.tokens[pr.keytoken];
1050+
size_t endlen = 0;
10501051

10511052
// TODO: TEST THIS CASE
10521053
// check once if our prefix is too long.
@@ -1059,6 +1060,12 @@ static void proxy_process_command(conn *c, char *command, size_t cmdlen, bool mu
10591060
return;
10601061
}
10611062

1063+
if (pr.request[pr.reqlen-2] == '\r') {
1064+
endlen = pr.reqlen - 2;
1065+
} else {
1066+
endlen = pr.reqlen - 1;
1067+
}
1068+
10621069
while (klen != 0) {
10631070
char temp[KEY_MAX_LENGTH + MAX_CMD_PREFIX + 30];
10641071
char *cur = temp;
@@ -1092,7 +1099,7 @@ static void proxy_process_command(conn *c, char *command, size_t cmdlen, bool mu
10921099
// Find the next key manually. This keeps the special cased code
10931100
// here instead of adding extra junk to the parser structure.
10941101
curkey += klen;
1095-
int remain = pr.endlen - (curkey - pr.request);
1102+
int remain = endlen - (curkey - pr.request);
10961103
while (remain) {
10971104
if (*curkey == ' ') {
10981105
remain--;

proxy.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ struct mcp_parser_s {
341341
uint8_t cmd_type; // command class.
342342
uint8_t keytoken; // because GAT. sigh. also cmds without a key.
343343
uint32_t reqlen; // full length of request buffer.
344-
uint32_t endlen; // index to the start of \r\n or \n
345344
int vlen;
346345
uint32_t klen; // length of key.
347346
bool noreply; // if quiet/noreply mode is set.

proxy_request.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,18 @@ int process_request(mcp_parser_t *pr, const char *command, size_t cmdlen) {
135135
// with a \r\n requirement but never did this and need backcompat.
136136
// In this case we _know_ \n is at cmdlen because we can't enter this
137137
// function otherwise.
138+
size_t endlen = 0;
138139
if (cm[cmdlen-2] == '\r') {
139-
pr->endlen = cmdlen - 2;
140+
endlen = cmdlen - 2;
140141
} else {
141-
pr->endlen = cmdlen - 1;
142+
endlen = cmdlen - 1;
142143
}
143144

144-
const char *s = memchr(command, ' ', pr->endlen);
145+
const char *s = memchr(command, ' ', endlen);
145146
if (s != NULL) {
146147
cl = s - command;
147148
} else {
148-
cl = pr->endlen;
149+
cl = endlen;
149150
}
150151
pr->keytoken = 0;
151152
pr->request = command;

0 commit comments

Comments
 (0)
0