PHP_HTTP_BUFFER_API php_http_buffer_t *php_http_buffer_from_string_ex(
php_http_buffer_t *buf, const char *str, size_t len)
{
- if ((buf = php_http_buffer_init(buf))) {
+ int free_buf = !!buf;
+
+ if (EXPECTED(buf = php_http_buffer_init(buf))) {
if (PHP_HTTP_BUFFER_NOMEM == php_http_buffer_append(buf, str, len)) {
- pefree(buf, buf->pmem);
+ if (free_buf) {
+ pefree(buf, buf->pmem);
+ }
buf = NULL;
}
}
if (buf->free < len) {
size_t size = override_size ? override_size : buf->size;
- while ((size + buf->free) < len) {
+ while (UNEXPECTED((size + buf->free) < len)) {
size <<= 1;
}
php_http_buffer_t *str;
size_t passed;
- if (!*s) {
+ if (UNEXPECTED(!*s)) {
*s = php_http_buffer_init_ex(NULL, chunk_size,
chunk_size ? PHP_HTTP_BUFFER_INIT_PREALLOC : 0);
}