Redundant if-clause in ImageData::paste

Issue #514 resolved
Anonymous created an issue

Hey there, I was the one that proposed that optimization a long while ago :P. Anyway, I was just looking at the revision to my code and noticed a redundancy in the last if-block. On line 136 it checks to see if "sh > 0"; two lines later, however, there's a for-block beginning with "i = 0; i < sh" which effectively performs the same operation. (Note that the "sw > 0" part of line 136 should still stick around.)

It's tiny and probably has a negligible performance improvement, but I thought I'd mention it since I noticed~

Comments (2)

  1. Boolsheet

    You are right, the for-loop condition would take care of zero or negative values. I saw it too after I suggested the change and it already was committed.

    However, the compiler is smart enough to optimize it out. For example, the Microsoft compiler uses the test instruction with the current code instead of cmp when sh > 0 is left out. This is (arguably) faster because it's shorter to encode and doesn't involve invoking a zero value from memory. I expect GCC an company to be just as smart.

    Anyway, it's not inside a loop and it's going to take 1 cycle either way so... ⛄

  2. Log in to comment