Here is a patch that replaces _cairo_restrict_value with a CLAMP macro. The macro works exactly like the CLAMP macro in glib. Doing it with a macro is of course faster, more readable (IMHO), and less code to keep around.
Created attachment 11916 [details] [review] Replace _cairo_restrict_value with CLAMP
The macro expands its arguments multiple times, so it's not a drop-in replacement. Our solution to the problem you raise is: first show us that it's a performance bottleneck, then move the function into the header and make it inline. Please reopen if you do that :)
(In reply to comment #2) > The macro expands its arguments multiple times, so it's not a drop-in > replacement. Our solution to the problem you raise is: first show us that it's > a performance bottleneck, then move the function into the header and make it > inline. FWIW, some time last year I also tried "fixing" clamping in cairo, but could never find a realistic test case that made _cairo_restrict_value (or any function that called it) take up a significant portion of the profile (even on ARM9 w/out FPU). After having said that, though, I hope you aren't discouraged from contributing to cairo. There's still plenty to do. Hope you stick around.
Just to clarify, the intention of the patch is not to fix a non-existent bottleneck. It is to make part of the code more readable. YMMV, but then you are wrong. :) And as you can see in the patch it doesn't matter if the constants 0.0 and 1.0 are expanded multiple times.
(In reply to comment #4) > Just to clarify, the intention of the patch is not to fix a non-existent > bottleneck. It is to make part of the code more readable. YMMV, but then you > are wrong. :) And as you can see in the patch it doesn't matter if the > constants 0.0 and 1.0 are expanded multiple times. +#define CLAMP(x, lo, hi) (((x) > (hi)) ? (hi) : (((x) < (lo)) ? (lo) : (x))) x is expanded at least twice. There's no point in fixing what's not broken.
Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.