-----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