2009/1/19 Stefan Dösinger stefan@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.
-----Original Message----- From: wine-devel-bounces@winehq.org [mailto:wine-devel- bounces@winehq.org] On Behalf Of Henri Verbeet Sent: Monday, January 19, 2009 12:48 PM To: wine-devel@winehq.org Subject: Re: [1/7] WineD3D: Don't single-allocate new gl shaders
2009/1/19 Stefan Dösinger stefan@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?
I once looked at the assembly, I think it does get rid of the floating point multiplication. A divide by 2 sounds better though.
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.
Actually I wanted to use it to restore the array in the case of a failure, apparently that got lost somewhere; "old_array" is shorter than "shader->gl_shaders" so I used it in the call.
I'll resend the patch wave without all the "use this instead" patches after AJ applied todays patches