Optimization: Removed unneeded strlen() calls several places.

This commit is contained in:
Jan Vidar Krey 2009-03-02 19:41:49 +01:00
parent ac56e7a5b9
commit 26766d8332
6 changed files with 16 additions and 16 deletions

View File

@ -53,7 +53,7 @@ static int check_cmd_bool(const char* cmd, struct linked_list* list, char* line,
data++; data++;
data = strip_white_space(data); data = strip_white_space(data);
if (!strlen(data)) if (!*data)
{ {
hub_log(log_fatal, "ACL parse error on line %d", line_count); hub_log(log_fatal, "ACL parse error on line %d", line_count);
return -1; return -1;
@ -80,7 +80,7 @@ static int check_cmd_user(const char* cmd, int status, struct linked_list* list,
data++; data++;
data = strip_white_space(data); data = strip_white_space(data);
if (!strlen(data)) if (!*data)
{ {
hub_log(log_fatal, "ACL parse error on line %d", line_count); hub_log(log_fatal, "ACL parse error on line %d", line_count);
return -1; return -1;
@ -192,7 +192,7 @@ static int check_cmd_addr(const char* cmd, struct linked_list* list, char* line,
data1++; data1++;
data1 = strip_white_space(data1); data1 = strip_white_space(data1);
if (!strlen(data1)) if (!*data1)
{ {
hub_log(log_fatal, "ACL parse error on line %d", line_count); hub_log(log_fatal, "ACL parse error on line %d", line_count);
return -1; return -1;
@ -266,7 +266,7 @@ static int acl_parse_line(char* line, int line_count, void* ptr_data)
pos[0] = 0; pos[0] = 0;
} }
if (strlen(line) == 0) if (!*line)
return 0; return 0;
#ifdef ACL_DEBUG #ifdef ACL_DEBUG
@ -274,7 +274,7 @@ static int acl_parse_line(char* line, int line_count, void* ptr_data)
#endif #endif
line = strip_white_space(line); line = strip_white_space(line);
if (!strlen(line)) if (!*line)
{ {
hub_log(log_fatal, "ACL parse error on line %d", line_count); hub_log(log_fatal, "ACL parse error on line %d", line_count);
return -1; return -1;
@ -328,7 +328,7 @@ int acl_initialize(struct hub_config* config, struct acl_handle* handle)
if (config) if (config)
{ {
if (strlen(config->file_acl) == 0) return 0; if (!*config->file_acl) return 0;
ret = file_read_lines(config->file_acl, handle, &acl_parse_line); ret = file_read_lines(config->file_acl, handle, &acl_parse_line);
if (ret == -1) if (ret == -1)

View File

@ -64,7 +64,7 @@
int val; \ int val; \
errno = 0; \ errno = 0; \
val = strtol(data, &endptr, 10); \ val = strtol(data, &endptr, 10); \
if (((errno == ERANGE && (val == INT_MAX || val == INT_MIN)) || (errno != 0 && val == 0)) || endptr == data /*|| endptr != &data[strlen(data)-1]*/) { \ if (((errno == ERANGE && (val == INT_MAX || val == INT_MIN)) || (errno != 0 && val == 0)) || endptr == data) { \
hub_log(log_fatal, "Configuration error on line %d: '%s' must be a number", line_count, key); \ hub_log(log_fatal, "Configuration error on line %d: '%s' must be a number", line_count, key); \
return -1; \ return -1; \
} \ } \
@ -458,7 +458,7 @@ static int config_parse_line(char* line, int line_count, void* ptr_data)
pos[0] = 0; pos[0] = 0;
} }
if (strlen(line) == 0) return 0; if (!*line) return 0;
#ifdef CONFIG_DUMP #ifdef CONFIG_DUMP
hub_log(log_trace, "config_parse_line(): '%s'", line); hub_log(log_trace, "config_parse_line(): '%s'", line);
@ -479,7 +479,7 @@ static int config_parse_line(char* line, int line_count, void* ptr_data)
key = strip_white_space(key); key = strip_white_space(key);
data = strip_white_space(data); data = strip_white_space(data);
if (!strlen(key) || !strlen(data)) if (!*key || !*data)
{ {
hub_log(log_fatal, "Configuration parse error on line %d", line_count); hub_log(log_fatal, "Configuration parse error on line %d", line_count);
return -1; return -1;

View File

@ -58,7 +58,7 @@ static int set_feature_cast_supports(struct user* u, struct adc_message* cmd)
it = &it[5]; it = &it[5];
} }
if (strlen(it) > 0) if (*it)
{ {
user_set_feature_cast_support(u, it); user_set_feature_cast_support(u, it);
} }

View File

@ -688,7 +688,7 @@ char* adc_msg_get_argument(struct adc_message* cmd, int offset)
argument[strlen(argument)-1] = 0; argument[strlen(argument)-1] = 0;
} }
if (strlen(argument)) if (*argument)
{ {
adc_msg_terminate(cmd); adc_msg_terminate(cmd);
return argument; return argument;

View File

@ -38,8 +38,8 @@ char* strip_white_space(char* string)
while (string[0] && is_white_space(string[0])) string++; while (string[0] && is_white_space(string[0])) string++;
if (!strlen(string)) if (!*string)
return string; return 0;
/* Strip appending whitespace */ /* Strip appending whitespace */
pos = &string[strlen(string)-1]; pos = &string[strlen(string)-1];
@ -187,7 +187,7 @@ int file_read_lines(const char* file, void* data, file_line_handler_t handler)
while ((pos = strchr(start, '\n'))) while ((pos = strchr(start, '\n')))
{ {
pos[0] = '\0'; pos[0] = '\0';
if (strlen(start) > 0) if (*start)
{ {
hub_log(log_dump, "Line: %s", start); hub_log(log_dump, "Line: %s", start);
if (handler(start, line_count+1, data) < 0) if (handler(start, line_count+1, data) < 0)
@ -197,7 +197,7 @@ int file_read_lines(const char* file, void* data, file_line_handler_t handler)
line_count++; line_count++;
} }
if (strlen(start) > 0) if (*start)
{ {
buf[strlen(start)] = 0; buf[strlen(start)] = 0;
hub_log(log_dump, "Line: %s", start); hub_log(log_dump, "Line: %s", start);

View File

@ -79,7 +79,7 @@ void net_on_read(int fd, short ev, void *arg)
while ((pos = strchr(start, '\n'))) while ((pos = strchr(start, '\n')))
{ {
pos[0] = '\0'; pos[0] = '\0';
if (strlen(start) > 0 && strlen(start) < user->hub->config->max_recv_buffer) if (*start && strlen(start) < user->hub->config->max_recv_buffer)
{ {
if (hub_handle_message(user, start, &pos[0]-&start[0]) == -1) if (hub_handle_message(user, start, &pos[0]-&start[0]) == -1)
{ {