Inline _cairo_restrict_value()

This is one instance where the function call overhead dominated the
function call in both time and size.
This commit is contained in:
Chris Wilson 2009-01-31 00:56:45 +00:00
parent cc8a09567c
commit d295942b9d
4 changed files with 35 additions and 33 deletions

View file

@ -384,15 +384,6 @@ _cairo_operator_bounded_by_source (cairo_operator_t op)
}
void
_cairo_restrict_value (double *value, double min, double max)
{
if (*value < min)
*value = min;
else if (*value > max)
*value = max;
}
/* This function is identical to the C99 function lround(), except that it
* performs arithmetic rounding (floor(d + .5) instead of away-from-zero rounding) and
* has a valid input range of (INT_MIN, INT_MAX] instead of

View file

@ -453,9 +453,9 @@ cairo_pattern_create_rgb (double red, double green, double blue)
{
cairo_color_t color;
_cairo_restrict_value (&red, 0.0, 1.0);
_cairo_restrict_value (&green, 0.0, 1.0);
_cairo_restrict_value (&blue, 0.0, 1.0);
red = _cairo_restrict_value (red, 0.0, 1.0);
green = _cairo_restrict_value (green, 0.0, 1.0);
blue = _cairo_restrict_value (blue, 0.0, 1.0);
_cairo_color_init_rgb (&color, red, green, blue);
@ -492,10 +492,10 @@ cairo_pattern_create_rgba (double red, double green, double blue,
{
cairo_color_t color;
_cairo_restrict_value (&red, 0.0, 1.0);
_cairo_restrict_value (&green, 0.0, 1.0);
_cairo_restrict_value (&blue, 0.0, 1.0);
_cairo_restrict_value (&alpha, 0.0, 1.0);
red = _cairo_restrict_value (red, 0.0, 1.0);
green = _cairo_restrict_value (green, 0.0, 1.0);
blue = _cairo_restrict_value (blue, 0.0, 1.0);
alpha = _cairo_restrict_value (alpha, 0.0, 1.0);
_cairo_color_init_rgba (&color, red, green, blue, alpha);
@ -949,10 +949,10 @@ cairo_pattern_add_color_stop_rgb (cairo_pattern_t *pattern,
return;
}
_cairo_restrict_value (&offset, 0.0, 1.0);
_cairo_restrict_value (&red, 0.0, 1.0);
_cairo_restrict_value (&green, 0.0, 1.0);
_cairo_restrict_value (&blue, 0.0, 1.0);
offset = _cairo_restrict_value (offset, 0.0, 1.0);
red = _cairo_restrict_value (red, 0.0, 1.0);
green = _cairo_restrict_value (green, 0.0, 1.0);
blue = _cairo_restrict_value (blue, 0.0, 1.0);
_cairo_pattern_add_color_stop ((cairo_gradient_pattern_t *) pattern,
offset, red, green, blue, 1.0);
@ -1003,11 +1003,11 @@ cairo_pattern_add_color_stop_rgba (cairo_pattern_t *pattern,
return;
}
_cairo_restrict_value (&offset, 0.0, 1.0);
_cairo_restrict_value (&red, 0.0, 1.0);
_cairo_restrict_value (&green, 0.0, 1.0);
_cairo_restrict_value (&blue, 0.0, 1.0);
_cairo_restrict_value (&alpha, 0.0, 1.0);
offset = _cairo_restrict_value (offset, 0.0, 1.0);
red = _cairo_restrict_value (red, 0.0, 1.0);
green = _cairo_restrict_value (green, 0.0, 1.0);
blue = _cairo_restrict_value (blue, 0.0, 1.0);
alpha = _cairo_restrict_value (alpha, 0.0, 1.0);
_cairo_pattern_add_color_stop ((cairo_gradient_pattern_t *) pattern,
offset, red, green, blue, alpha);

View file

@ -648,10 +648,10 @@ _current_source_matches_solid (cairo_t *cr,
if (current->type != CAIRO_PATTERN_TYPE_SOLID)
return FALSE;
_cairo_restrict_value (&red, 0.0, 1.0);
_cairo_restrict_value (&green, 0.0, 1.0);
_cairo_restrict_value (&blue, 0.0, 1.0);
_cairo_restrict_value (&alpha, 0.0, 1.0);
red = _cairo_restrict_value (red, 0.0, 1.0);
green = _cairo_restrict_value (green, 0.0, 1.0);
blue = _cairo_restrict_value (blue, 0.0, 1.0);
alpha = _cairo_restrict_value (alpha, 0.0, 1.0);
_cairo_color_init_rgba (&color, red, green, blue, alpha);
return _cairo_color_equal (&color,
@ -868,7 +868,8 @@ cairo_set_tolerance (cairo_t *cr, double tolerance)
if (cr->status)
return;
_cairo_restrict_value (&tolerance, CAIRO_TOLERANCE_MINIMUM, tolerance);
if (tolerance < CAIRO_TOLERANCE_MINIMUM)
tolerance = CAIRO_TOLERANCE_MINIMUM;
status = _cairo_gstate_set_tolerance (cr->gstate, tolerance);
if (unlikely (status))
@ -962,7 +963,8 @@ cairo_set_line_width (cairo_t *cr, double width)
if (cr->status)
return;
_cairo_restrict_value (&width, 0.0, width);
if (width < 0.)
width = 0.;
status = _cairo_gstate_set_line_width (cr->gstate, width);
if (unlikely (status))

View file

@ -1032,8 +1032,17 @@ typedef struct _cairo_stroke_face {
} cairo_stroke_face_t;
/* cairo.c */
cairo_private void
_cairo_restrict_value (double *value, double min, double max);
static inline double
_cairo_restrict_value (double value, double min, double max)
{
if (value < min)
return min;
else if (value > max)
return max;
else
return value;
}
/* C99 round() rounds to the nearest integral value with halfway cases rounded
* away from 0. _cairo_round rounds halfway cases toward negative infinity.