[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [gnurl] 121/205: conncache: make hashkey avoid malloc
From: |
gnunet |
Subject: |
[GNUnet-SVN] [gnurl] 121/205: conncache: make hashkey avoid malloc |
Date: |
Thu, 20 Apr 2017 16:21:01 +0200 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to annotated tag gnurl-7.54.0
in repository gnurl.
commit 2066072ff20bea7a25d5506ab3ed7f9547f1f010
Author: Daniel Stenberg <address@hidden>
AuthorDate: Tue Mar 28 19:18:24 2017 +0200
conncache: make hashkey avoid malloc
... to make it much faster. Idea developed with primepie on IRC.
Closes #1365
---
lib/conncache.c | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/lib/conncache.c b/lib/conncache.c
index a51c8fd76..7143ff83a 100644
--- a/lib/conncache.c
+++ b/lib/conncache.c
@@ -5,8 +5,8 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2012, 2016, Linus Nielsen Feltzing, <address@hidden>
- * Copyright (C) 2012 - 2015, Daniel Stenberg, <address@hidden>, et al.
+ * Copyright (C) 2012 - 2016, Linus Nielsen Feltzing, <address@hidden>
+ * Copyright (C) 2012 - 2017, Daniel Stenberg, <address@hidden>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -127,8 +127,9 @@ void Curl_conncache_destroy(struct conncache *connc)
Curl_hash_destroy(&connc->hash);
}
-/* returns an allocated key to find a bundle for this connection */
-static char *hashkey(struct connectdata *conn)
+/* creates a key to find a bundle for this connection */
+static void hashkey(struct connectdata *conn, char *buf,
+ size_t len) /* something like 128 is fine */
{
const char *hostname;
@@ -141,7 +142,10 @@ static char *hashkey(struct connectdata *conn)
else
hostname = conn->host.name;
- return aprintf("%s:%ld", hostname, conn->port);
+ DEBUGASSERT(len > 32);
+
+ /* put the number first so that the hostname gets cut off if too long */
+ snprintf(buf, len, "%ld%s", conn->port, hostname);
}
/* Look up the bundle with all the connections to the same host this
@@ -151,11 +155,9 @@ struct connectbundle *Curl_conncache_find_bundle(struct
connectdata *conn,
{
struct connectbundle *bundle = NULL;
if(connc) {
- char *key = hashkey(conn);
- if(key) {
- bundle = Curl_hash_pick(&connc->hash, key, strlen(key));
- free(key);
- }
+ char key[128];
+ hashkey(conn, key, sizeof(key));
+ bundle = Curl_hash_pick(&connc->hash, key, strlen(key));
}
return bundle;
@@ -204,21 +206,16 @@ CURLcode Curl_conncache_add_conn(struct conncache *connc,
bundle = Curl_conncache_find_bundle(conn, data->state.conn_cache);
if(!bundle) {
- char *key;
int rc;
+ char key[128];
result = bundle_create(data, &new_bundle);
if(result)
return result;
- key = hashkey(conn);
- if(!key) {
- bundle_destroy(new_bundle);
- return CURLE_OUT_OF_MEMORY;
- }
-
+ hashkey(conn, key, sizeof(key));
rc = conncache_add_bundle(data->state.conn_cache, key, new_bundle);
- free(key);
+
if(!rc) {
bundle_destroy(new_bundle);
return CURLE_OUT_OF_MEMORY;
--
To stop receiving notification emails like this one, please contact
address@hidden
- [GNUnet-SVN] [gnurl] 103/205: CURLINFO_PRIMARY_IP.3: add example, (continued)
- [GNUnet-SVN] [gnurl] 103/205: CURLINFO_PRIMARY_IP.3: add example, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 81/205: BINDINGS: a Delphi binding, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 119/205: pause: handle mixed types of data when paused, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 31/205: ares: return error at once if timed out before name resolve starts, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 126/205: NTLM: check for features with #ifdef instead of #if, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 143/205: docs: Explain --fail-early does not imply --fail, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 142/205: telnet: (win32) fix read callback return variable, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 169/205: gtls: fix compiler warning, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 152/205: hash: move key into hash struct to reduce mallocs, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 199/205: openssl: fix thread-safety bugs in error-handling, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 121/205: conncache: make hashkey avoid malloc,
gnunet <=
- [GNUnet-SVN] [gnurl] 167/205: low_speed_limit: improved function for longer time periods, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 157/205: multi: fix queueing of pending easy handles, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 78/205: Improve code readbility, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 118/205: http: Fix proxy connection reuse with basic-auth, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 108/205: asiohiper: make sure socket is open in event_cb, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 140/205: libcurl.def: removed, unused, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 182/205: openssl: fix this statement may fall through [-Wimplicit-fallthrough=], gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 48/205: insecure.d: clarify that this is for server connections, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 147/205: multi: make curl_multi_wait avoid malloc in the typical case, gnunet, 2017/04/20
- [GNUnet-SVN] [gnurl] 196/205: extern-scan.pl: strip trailing CR, gnunet, 2017/04/20