3 ms·
This example becomes much stronger when you have more than one rasterize function. Writing 3 separate functions for 3 pixel types is reasonable. Writing 9 func
by corysama 16y ago
This example becomes much stronger when you have more than one rasterize function. Writing 3 separate functions for 3 pixel types is reasonable. Writing 9 functions for 3 pixel types * 3 rasterization styles is repetitive and error-prone. Writing 27 separate functions because you added 3 blend modes is very, very bad.
At that point in C, you either start writing "creative" preprocessor macros, write a custom code generator or give up and eat the performance penalty of the run-time solution. A rasterization function needs to perform on the order of 1024x768x30 calls per second on the low end. Compared to inlinable static function calls, function pointer overhead becomes a big deal at that scale.
"Creative" template abuse can be much worse than "creative" preprocessor abuse. However, elegant application of templates, such as policy-based design, can solve code permutation situations without repetition or performance problems.