Branch: Tag:

2017-01-01

2017-01-01 17:51:41 by Arne Goedeke <el@laramies.com>

Stdio.File()->read: optimize buffer size

This change makes sure that the read buffer size will always exactly be
as big as the data we want to read. This usually saves one realloc().

746:   {    size_t bytes = r;    struct byte_buffer buf = BUFFER_INIT(); -  int e = 0, nomem = 0; +  int e = 0;       THREADS_ALLOW();   
754:    size_t len = MINIMUM(DIRECT_BUFSIZE, bytes);    ptrdiff_t i;    -  if (UNLIKELY(!buffer_ensure_space_nothrow(&buf, len))) { +  /* make space for exactly len bytes plus the terminating null byte */ +  if (UNLIKELY(!buffer_make_space_nothrow(&buf, len+1))) {    buffer_free(&buf);    e = ENOMEM;    break;