Skip to content

Commit

Permalink
Inline _cairo_restrict_value()
Browse files Browse the repository at this point in the history
This is one instance where the function call overhead dominated the
function call in both time and size.
  • Loading branch information
ickle committed Feb 13, 2009
1 parent cc8a095 commit d295942
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
9 changes: 0 additions & 9 deletions src/cairo-misc.c
Expand Up @@ -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
Expand Down
32 changes: 16 additions & 16 deletions src/cairo-pattern.c
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 8 additions & 6 deletions src/cairo.c
Expand Up @@ -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,
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down
13 changes: 11 additions & 2 deletions src/cairoint.h
Expand Up @@ -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.
Expand Down

0 comments on commit d295942

Please sign in to comment.