On Wed, 30 Sep 2020 at 18:44, Zebediah Figura zfigura@codeweavers.com wrote:
On 9/30/20 9:16 AM, Henri Verbeet wrote:
case STATE_SHADER_PIXEL:
if (!shader_source)
{
shader_source = strdup(line);
}
else
{
shader_source = realloc(shader_source, strlen(shader_source) + strlen(line) + 1);
strcat(shader_source, line);
This isn't terribly efficient. (Both the strcat() after strlen(), and the realloc() strategy.) It probably doesn't really matter in practice, but we wouldn't want to set any bad examples.
I guess you're proposing to instead use something like array_reserve(), and e.g.
len = strlen(line); ... memcpy(shader_source + source_len, line, len);
Both of which struck me as extra complexity for not much reason, but I don't care too much...
array_reserve() is probably overkill, although chances are we'll need it at some point in the future anyway. Simply doubling the allocation would have been fine too. The alternative I was thinking of though, was to simply read/map the entire input file into memory at once, and then simply pass a pointer into the input file to D3DCompile().