conncache: eliminate conn->destination_len as premature optimization

Closes #16792
This commit is contained in:
Stefan Eissing 2025-03-22 10:47:08 +01:00 committed by Daniel Stenberg
parent 646b2d6ca2
commit ec4e2cd15d
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
4 changed files with 13 additions and 14 deletions

View File

@ -88,16 +88,17 @@ static void cpool_discard_conn(struct cpool *cpool,
struct connectdata *conn, struct connectdata *conn,
bool aborted); bool aborted);
static struct cpool_bundle *cpool_bundle_create(const char *dest, static struct cpool_bundle *cpool_bundle_create(const char *dest)
size_t dest_len)
{ {
struct cpool_bundle *bundle; struct cpool_bundle *bundle;
size_t dest_len = strlen(dest);
bundle = calloc(1, sizeof(*bundle) + dest_len); bundle = calloc(1, sizeof(*bundle) + dest_len);
if(!bundle) if(!bundle)
return NULL; return NULL;
Curl_llist_init(&bundle->conns, NULL); Curl_llist_init(&bundle->conns, NULL);
bundle->dest_len = dest_len; bundle->dest_len = dest_len + 1;
memcpy(bundle->dest, dest, dest_len); memcpy(bundle->dest, dest, bundle->dest_len);
return bundle; return bundle;
} }
@ -176,7 +177,7 @@ static struct cpool_bundle *cpool_find_bundle(struct cpool *cpool,
struct connectdata *conn) struct connectdata *conn)
{ {
return Curl_hash_pick(&cpool->dest2bundle, return Curl_hash_pick(&cpool->dest2bundle,
conn->destination, conn->destination_len); conn->destination, strlen(conn->destination) + 1);
} }
@ -276,7 +277,7 @@ cpool_add_bundle(struct cpool *cpool, struct connectdata *conn)
{ {
struct cpool_bundle *bundle; struct cpool_bundle *bundle;
bundle = cpool_bundle_create(conn->destination, conn->destination_len); bundle = cpool_bundle_create(conn->destination);
if(!bundle) if(!bundle)
return NULL; return NULL;
@ -551,7 +552,7 @@ bool Curl_cpool_conn_now_idle(struct Curl_easy *data,
} }
bool Curl_cpool_find(struct Curl_easy *data, bool Curl_cpool_find(struct Curl_easy *data,
const char *destination, size_t dest_len, const char *destination,
Curl_cpool_conn_match_cb *conn_cb, Curl_cpool_conn_match_cb *conn_cb,
Curl_cpool_done_match_cb *done_cb, Curl_cpool_done_match_cb *done_cb,
void *userdata) void *userdata)
@ -567,7 +568,8 @@ bool Curl_cpool_find(struct Curl_easy *data,
CPOOL_LOCK(cpool, data); CPOOL_LOCK(cpool, data);
bundle = Curl_hash_pick(&cpool->dest2bundle, bundle = Curl_hash_pick(&cpool->dest2bundle,
CURL_UNCONST(destination), dest_len); CURL_UNCONST(destination),
strlen(destination) + 1);
if(bundle) { if(bundle) {
struct Curl_llist_node *curr = Curl_llist_head(&bundle->conns); struct Curl_llist_node *curr = Curl_llist_head(&bundle->conns);
while(curr) { while(curr) {

View File

@ -121,14 +121,13 @@ typedef bool Curl_cpool_done_match_cb(bool result, void *userdata);
* All callbacks are invoked while the pool's lock is held. * All callbacks are invoked while the pool's lock is held.
* @param data current transfer * @param data current transfer
* @param destination match agaonst `conn->destination` in pool * @param destination match agaonst `conn->destination` in pool
* @param dest_len destination length, including terminating NUL
* @param conn_cb must be present, called for each connection in the * @param conn_cb must be present, called for each connection in the
* bundle until it returns TRUE * bundle until it returns TRUE
* @return combined result of last conn_db and result_cb or FALSE if no * @return combined result of last conn_db and result_cb or FALSE if no
connections were present. connections were present.
*/ */
bool Curl_cpool_find(struct Curl_easy *data, bool Curl_cpool_find(struct Curl_easy *data,
const char *destination, size_t dest_len, const char *destination,
Curl_cpool_conn_match_cb *conn_cb, Curl_cpool_conn_match_cb *conn_cb,
Curl_cpool_done_match_cb *done_cb, Curl_cpool_done_match_cb *done_cb,
void *userdata); void *userdata);

View File

@ -1288,7 +1288,7 @@ ConnectionExists(struct Curl_easy *data,
/* Find a connection in the pool that matches what "data + needle" /* Find a connection in the pool that matches what "data + needle"
* requires. If a suitable candidate is found, it is attached to "data". */ * requires. If a suitable candidate is found, it is attached to "data". */
result = Curl_cpool_find(data, needle->destination, needle->destination_len, result = Curl_cpool_find(data, needle->destination,
url_match_conn, url_match_result, &match); url_match_conn, url_match_result, &match);
/* wait_pipe is TRUE if we encounter a bundle that is undecided. There /* wait_pipe is TRUE if we encounter a bundle that is undecided. There
@ -2064,9 +2064,8 @@ static CURLcode setup_connection_internals(struct Curl_easy *data,
if(!conn->destination) if(!conn->destination)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
conn->destination_len = strlen(conn->destination) + 1;
Curl_strntolower(conn->destination, conn->destination, Curl_strntolower(conn->destination, conn->destination,
conn->destination_len - 1); strlen(conn->destination));
return CURLE_OK; return CURLE_OK;
} }

View File

@ -770,7 +770,6 @@ struct connectdata {
curl_off_t connection_id; /* Contains a unique number to make it easier to curl_off_t connection_id; /* Contains a unique number to make it easier to
track the connections in the log output */ track the connections in the log output */
char *destination; /* string carrying normalized hostname+port+scope */ char *destination; /* string carrying normalized hostname+port+scope */
size_t destination_len; /* strlen(destination) + 1 */
/* 'dns_entry' is the particular host we use. This points to an entry in the /* 'dns_entry' is the particular host we use. This points to an entry in the
DNS cache and it will not get pruned while locked. It gets unlocked in DNS cache and it will not get pruned while locked. It gets unlocked in