diff --git a/service-src/hashid.h b/service-src/hashid.h index dc410eb2..501addcd 100644 --- a/service-src/hashid.h +++ b/service-src/hashid.h @@ -19,12 +19,15 @@ struct hashid { }; static void -hashid_init(struct hashid *hi, int max, int hashcap) { +hashid_init(struct hashid *hi, int max) { int i; - assert((hashcap & (hashcap-1))==0); - hi->cap = max; - assert(hi->cap <= hashcap); + int hashcap; + hashcap = 16; + while (hashcap < max) { + hashcap *= 2; + } hi->hashmod = hashcap - 1; + hi->cap = max; hi->count = 0; hi->id = malloc(max * sizeof(struct hashid_node)); for (i=0;icap;i++) { - int index = (i+hi->count) % hi->cap; + int index = (i+id) % hi->cap; if (hi->id[index].id == -1) { c = &hi->id[index]; break; diff --git a/service-src/service_gate.c b/service-src/service_gate.c index a97dfdcf..fc1553c4 100644 --- a/service-src/service_gate.c +++ b/service-src/service_gate.c @@ -368,11 +368,7 @@ gate_init(struct gate *g , struct skynet_context * ctx, char * parm) { g->ctx = ctx; - int cap = 16; - while (cap < max) { - cap *= 2; - } - hashid_init(&g->hash, max, cap); + hashid_init(&g->hash, max); g->conn = malloc(max * sizeof(struct connection)); memset(g->conn, 0, max *sizeof(struct connection)); g->max_connection = max;