[SVN] Revision 1300
Chris Thomas
chris at cjack.com
Wed Jul 6 03:01:01 UTC 2005
On Jul 5, 2005, at 6:08 PM, Kevin Ballard wrote:
> Tweaked the coloring code to use a simple macro instead of the
> silly multi-line inline function for converting color values
> -#define RGB8ComponentTransform(component) (component == 0 ? 0.0 :
> 1.0/(255.0/component))
> +
> +static inline float RGB8ComponentTransform( unsigned char component )
> +{
> + // prevent division by zero
> + if(component == 0)
> + {
> + return 0.0;
> + }
> +
> + return (1.0/(255.0/component));
> +}
• In general, this sort of change isn't worth the effort. If the
compiler (in optimized mode) doesn't compile this to identical
assembly, the compiler is a very poor one, and GCC 3.x in particular
does just fine.
• I had intentionally avoided using a macro because it introduces a
source of subtle bugs:
RGB8ComponentTransform( 0x11 * 3 ) == (0x11*3 == 0 ? 0.0 : 1.0/
(255.0/0x11*3))
Currently, all the values passed are constant, but they needn't
always be.
You can fix the example I give above by placing parenthesis around
"component" wherever it appears in the macro, but then you still have
other preprocessor issues, like poor error messages for problems in
macro substitutions.
Chris
More information about the textmate-dev
mailing list