Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
d55d5c5d
Commit
d55d5c5d
authored
May 28, 2010
by
antirez
Browse files
command table size calculated with sizeof
parent
1a132bbc
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
d55d5c5d
...
@@ -753,7 +753,6 @@ static void unwatchCommand(redisClient *c);
...
@@ -753,7 +753,6 @@ static void unwatchCommand(redisClient *c);
/* Global vars */
/* Global vars */
static struct redisServer server; /* server global state */
static struct redisServer server; /* server global state */
static struct redisCommand *commandTable;
static struct redisCommand *commandTable;
static unsigned int commandTableSize;
static struct redisCommand readonlyCommandTable[] = {
static struct redisCommand readonlyCommandTable[] = {
{"get",getCommand,2,REDIS_CMD_INLINE,NULL,1,1,1},
{"get",getCommand,2,REDIS_CMD_INLINE,NULL,1,1,1},
{"set",setCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM,NULL,0,0,0},
{"set",setCommand,3,REDIS_CMD_BULK|REDIS_CMD_DENYOOM,NULL,0,0,0},
...
@@ -862,8 +861,7 @@ static struct redisCommand readonlyCommandTable[] = {
...
@@ -862,8 +861,7 @@ static struct redisCommand readonlyCommandTable[] = {
{"punsubscribe",punsubscribeCommand,-1,REDIS_CMD_INLINE,NULL,0,0,0},
{"punsubscribe",punsubscribeCommand,-1,REDIS_CMD_INLINE,NULL,0,0,0},
{"publish",publishCommand,3,REDIS_CMD_BULK|REDIS_CMD_FORCE_REPLICATION,NULL,0,0,0},
{"publish",publishCommand,3,REDIS_CMD_BULK|REDIS_CMD_FORCE_REPLICATION,NULL,0,0,0},
{"watch",watchCommand,-2,REDIS_CMD_INLINE,NULL,0,0,0},
{"watch",watchCommand,-2,REDIS_CMD_INLINE,NULL,0,0,0},
{"unwatch",unwatchCommand,1,REDIS_CMD_INLINE,NULL,0,0,0},
{"unwatch",unwatchCommand,1,REDIS_CMD_INLINE,NULL,0,0,0}
{NULL,NULL,0,0,NULL,0,0,0}
};
};
/*============================ Utility functions ============================ */
/*============================ Utility functions ============================ */
...
@@ -2256,16 +2254,12 @@ static int qsortRedisCommands(const void *r1, const void *r2) {
...
@@ -2256,16 +2254,12 @@ static int qsortRedisCommands(const void *r1, const void *r2) {
}
}
static void sortCommandTable() {
static void sortCommandTable() {
int i = 0, size = 0;
/* Determine and store the size of the command table */
while(readonlyCommandTable[i++].name != NULL) size++;
commandTableSize = size;
/* Copy and sort the read-only version of the command table */
/* Copy and sort the read-only version of the command table */
commandTable = (struct redisCommand*)malloc(sizeof(readonlyCommandTable));
commandTable = (struct redisCommand*)malloc(sizeof(readonlyCommandTable));
memcpy(commandTable,readonlyCommandTable,sizeof(readonlyCommandTable));
memcpy(commandTable,readonlyCommandTable,sizeof(readonlyCommandTable));
qsort(commandTable,size,sizeof(struct redisCommand),qsortRedisCommands);
qsort(commandTable,
sizeof(readonlyCommandTable)/sizeof(struct redisCommand),
sizeof(struct redisCommand),qsortRedisCommands);
}
}
static struct redisCommand *lookupCommand(char *name) {
static struct redisCommand *lookupCommand(char *name) {
...
@@ -2273,7 +2267,7 @@ static struct redisCommand *lookupCommand(char *name) {
...
@@ -2273,7 +2267,7 @@ static struct redisCommand *lookupCommand(char *name) {
return bsearch(
return bsearch(
&tmp,
&tmp,
commandTable,
commandTable,
commandTableSize
,
sizeof(readonlyCommandTable)/sizeof(struct redisCommand)
,
sizeof(struct redisCommand),
sizeof(struct redisCommand),
qsortRedisCommands);
qsortRedisCommands);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment