conncache: make hashkey avoid malloc #1365

Closed
wants to merge 1 commit into
from

Projects

None yet

3 participants

@bagder
Owner
bagder commented Mar 28, 2017

... to make it much faster. Idea developed with primepie on IRC.

@bagder bagder conncache: make hashkey avoid malloc
... to make it much faster. Idea developed with primepie on IRC.
9cc51a6

@bagder, thanks for your PR! By analyzing the history of the files in this pull request, we identified @yangtse, @linusnielsen and @mkauf to be potential reviewers.

+ 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);
MarcelRaad
MarcelRaad Mar 28, 2017 Member

Isn't snprintf C99? I believe MSVC versions prior to 2015 only have a _snprintf that doesn't append a '\0' if the string gets truncated.

bagder
bagder Mar 28, 2017 Owner

That's one of the reasons why have our own set of *printf() implementations and snprintf comes from here: https://github.com/curl/curl/blob/master/lib/curlx.h#L105

If you check the code closer you'll see that we already use snprintf() in numerous places thanks to this.

MarcelRaad
MarcelRaad Mar 28, 2017 Member

Ah, great! I forgot about that.

@MarcelRaad

Good idea!

@@ -128,7 +128,8 @@ void Curl_conncache_destroy(struct conncache *connc)
}
/* returns an allocated key to find a bundle for this connection */
bagder
bagder Mar 28, 2017 Owner

I'll fix the comment too.

@bagder bagder added a commit that closed this pull request Mar 28, 2017
@bagder bagder conncache: make hashkey avoid malloc
... to make it much faster. Idea developed with primepie on IRC.

Closes #1365
2066072
@bagder bagder closed this in 2066072 Mar 28, 2017
Owner
bagder commented Mar 28, 2017

thanks for the review!

@bagder bagder deleted the bagder/improve-hashkey branch Mar 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment