[PATCH vkd3d 1/3] vkd3d-shader: Don't resize the buffer when there is enough free space.

Henri Verbeet hverbeet at gmail.com
Mon Aug 16 11:04:33 CDT 2021


On Fri, 13 Aug 2021 at 16:15, Matteo Bruni <mbruni at codeweavers.com> wrote:
>  static bool vkd3d_string_buffer_resize(struct vkd3d_string_buffer *buffer, int rc)
>  {
> -    unsigned int new_buffer_size = buffer->buffer_size * 2;
> +    unsigned int new_buffer_size = max(buffer->buffer_size * 2, 32);
>      char *new_buffer;
>
> -    new_buffer_size = max(new_buffer_size, 32);
> +    if (rc < buffer->buffer_size - buffer->content_size)
> +        return true;
> +
That doesn't quite handle the case where "rc" is -1. Perhaps it's fine
to assume it isn't these days, but in that case we might as well get
rid of the rest of the code handling that case as well. The patch also
seems a little superfluous though; we already have a similar check in
vkd3d_string_buffer_vprintf().

We would do an unnecessary resize when calling
vkd3d_string_buffer_vprintf() the first time after a
vkd3d_string_buffer_clear(), although the best way to fix that would
seem to be simply getting rid of the vkd3d_string_buffer_resize() call
responsible for that, like patch 2/3 in this series does. It was added
by commit 5fb9bcdd148ed728d90a420f209cdfcc03af24ac, but that same
commit also adds the max() in vkd3d_string_buffer_resize() that should
make it superfluous.



More information about the wine-devel mailing list