2009/1/19 Stefan Dösinger <stefan(a)codeweavers.com>:
+ shader->shader_array_size += max(1, old_size * 0.5); I don't know for sure if the compiler is able to get rid of the floating point multiplication, but wouldn't a right shift or divide by 2 work at least as well?
+ shader->gl_shaders = HeapReAlloc(GetProcessHeap(), 0, old_array, + (shader->shader_array_size + 1) * sizeof(*shader->gl_shaders)); This looks more complicated than it has to be. It's easier to just change "old_size <= shader->num_gl_shaders" into "old_size < shader->num_gl_shaders" and drop the +1 here. Also note that "old_array" isn't particularly useful here, you overwrite shader->gl_shaders regardless of whether the allocation fails or succeeds.
The typical way to do this would be: if (shader->num_gl_shaders >= shader->shader_array_size) { UINT new_size; struct ps_compiled_shader *new_array; if (shader->gl_shaders) { new_size = shader->shader_array_size << 1; new_array = HeapReAlloc(GetProcessHeap(), 0, shader->gl_shaders, new_size * sizeof(*new_array)); } else { new_size = 1; new_array = HeapAlloc(GetProcessHeap(), 0, new_size * sizeof(*new_array)); } if (!new_array) { ERR("Out of memory\n"); return 0; } shader->shader_array_size = new_size; shader->gl_shaders = new_array; } This applies to 4/7 as well.