mirror of
https://github.com/curl/curl.git
synced 2026-08-24 13:03:35 +03:00
urlapi: leaner with fewer allocs
Slightly faster with more robust code. Uses fewer and smaller mallocs. - remove two fields from the URL handle struct - reduce copies and allocs - use dynbuf buffers more instead of custom malloc + copies - uses dynbuf to build the host name in reduces serial alloc+free within the same function. - move dedotdotify into urlapi.c and make it static, not strdup the input and optimize it by checking for . and / before using strncmp - remove a few strlen() calls - add Curl_dyn_setlen() that can "trim" an existing dynbuf Closes #9408
This commit is contained in:
parent
2ae81e680b
commit
f703cf971c
11 changed files with 565 additions and 596 deletions
17
lib/dynbuf.c
17
lib/dynbuf.c
|
|
@ -128,7 +128,6 @@ void Curl_dyn_reset(struct dynbuf *s)
|
|||
s->leng = 0;
|
||||
}
|
||||
|
||||
#ifdef USE_NGTCP2
|
||||
/*
|
||||
* Specify the size of the tail to keep (number of bytes from the end of the
|
||||
* buffer). The rest will be dropped.
|
||||
|
|
@ -153,7 +152,6 @@ CURLcode Curl_dyn_tail(struct dynbuf *s, size_t trail)
|
|||
return CURLE_OK;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Appends a buffer with length.
|
||||
|
|
@ -255,3 +253,18 @@ size_t Curl_dyn_len(const struct dynbuf *s)
|
|||
DEBUGASSERT(!s->leng || s->bufr);
|
||||
return s->leng;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set a new (smaller) length.
|
||||
*/
|
||||
CURLcode Curl_dyn_setlen(struct dynbuf *s, size_t set)
|
||||
{
|
||||
DEBUGASSERT(s);
|
||||
DEBUGASSERT(s->init == DYNINIT);
|
||||
DEBUGASSERT(!s->leng || s->bufr);
|
||||
if(set > s->leng)
|
||||
return CURLE_BAD_FUNCTION_ARGUMENT;
|
||||
s->leng = set;
|
||||
s->bufr[s->leng] = 0;
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue