performance opt.: replace sprintf
parent
da2ddc7441
commit
ba87f8e1ea
|
|
@ -174,6 +174,7 @@ static struct fast_task_info *alloc_channel_task(IdempotencyClientChannel
|
||||||
*channel, const uint32_t hash_code, const FCCommunicationType comm_type,
|
*channel, const uint32_t hash_code, const FCCommunicationType comm_type,
|
||||||
const char *server_ip, const uint16_t port, int *err_no)
|
const char *server_ip, const uint16_t port, int *err_no)
|
||||||
{
|
{
|
||||||
|
int len;
|
||||||
struct fast_task_info *task;
|
struct fast_task_info *task;
|
||||||
SFAddressFamilyHandler *fh;
|
SFAddressFamilyHandler *fh;
|
||||||
SFNetworkHandler *handler;
|
SFNetworkHandler *handler;
|
||||||
|
|
@ -194,7 +195,12 @@ static struct fast_task_info *alloc_channel_task(IdempotencyClientChannel
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(task->server_ip, sizeof(task->server_ip), "%s", server_ip);
|
len = strlen(server_ip);
|
||||||
|
if (len >= sizeof(task->server_ip)) {
|
||||||
|
len = sizeof(task->server_ip) - 1;
|
||||||
|
}
|
||||||
|
memcpy(task->server_ip, server_ip, len);
|
||||||
|
*(task->server_ip + len) = '\0';
|
||||||
task->port = port;
|
task->port = port;
|
||||||
task->arg = channel;
|
task->arg = channel;
|
||||||
task->thread_data = g_sf_context.thread_data +
|
task->thread_data = g_sf_context.thread_data +
|
||||||
|
|
@ -255,7 +261,10 @@ struct idempotency_client_channel *idempotency_client_channel_get(
|
||||||
IdempotencyClientChannel *current;
|
IdempotencyClientChannel *current;
|
||||||
IdempotencyClientChannel *channel;
|
IdempotencyClientChannel *channel;
|
||||||
|
|
||||||
key_len = snprintf(key, sizeof(key), "%s-%u", server_ip, server_port);
|
key_len = strlen(server_ip);
|
||||||
|
memcpy(key, server_ip, key_len);
|
||||||
|
*(key + key_len++) = '-';
|
||||||
|
key_len += fc_itoa(server_port, key + key_len);
|
||||||
hash_code = fc_simple_hash(key, key_len);
|
hash_code = fc_simple_hash(key, key_len);
|
||||||
bucket = channel_context.htable.buckets +
|
bucket = channel_context.htable.buckets +
|
||||||
hash_code % channel_context.htable.capacity;
|
hash_code % channel_context.htable.capacity;
|
||||||
|
|
|
||||||
|
|
@ -186,9 +186,11 @@ static int save(SFBinlogIndexContext *ctx, const char *filename)
|
||||||
result = 0;
|
result = 0;
|
||||||
p = buff;
|
p = buff;
|
||||||
bend = buff + sizeof(buff);
|
bend = buff + sizeof(buff);
|
||||||
p += sprintf(p, "%d %"PRId64"\n",
|
|
||||||
ctx->index_array.count,
|
p += fc_itoa(ctx->index_array.count, p);
|
||||||
ctx->last_version);
|
*p++ = ' ';
|
||||||
|
p += fc_itoa(ctx->last_version, p);
|
||||||
|
*p++ = '\n';
|
||||||
|
|
||||||
index = ctx->index_array.indexes;
|
index = ctx->index_array.indexes;
|
||||||
for (i=0; i<ctx->index_array.count; i++) {
|
for (i=0; i<ctx->index_array.count; i++) {
|
||||||
|
|
|
||||||
|
|
@ -865,8 +865,7 @@ static void combine_bind_addr(char *bind_addr, const char *ip_addr)
|
||||||
p = bind_addr + strlen(bind_addr);
|
p = bind_addr + strlen(bind_addr);
|
||||||
*p++ = ',';
|
*p++ = ',';
|
||||||
}
|
}
|
||||||
|
strcpy(p, ip_addr);
|
||||||
sprintf(p, "%s", ip_addr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *get_address_family_caption(
|
static const char *get_address_family_caption(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue