diff options
author | Frediano Ziglio <fziglio@redhat.com> | 2015-08-21 10:46:58 +0100 |
---|---|---|
committer | Frediano Ziglio <freddy77@gmail.com> | 2023-11-22 07:45:06 +0000 |
commit | ef64aeba614be5a2cbc3491361b1c6363c18db37 (patch) | |
tree | 3f13d609e351febf66e400bb51ec8462a42d6ac5 | |
parent | 05378ee4727c42077c4f4ebc69ea3261d0b7a4e1 (diff) |
optimize end of row check for images
Doing profiles reveals that the check for "is this pixel at end of row?"
if ((cur_pix + 1 - lines) % width == 0)
leads to 2 divisions, one to compute (cur_pix + 1 - lines) (divided by
sizeof(*cur_pix) which could be 3) and one for (x % width).
Although the substituted code looks more long is faster as it does not
involve divisions.
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
-rw-r--r-- | server/spice-bitmap-utils.tmpl.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/server/spice-bitmap-utils.tmpl.c b/server/spice-bitmap-utils.tmpl.c index a104cb27..7033476b 100644 --- a/server/spice-bitmap-utils.tmpl.c +++ b/server/spice-bitmap-utils.tmpl.c @@ -118,7 +118,8 @@ static void FNAME(compute_lines_gradual_score)(PIXEL *lines, int width, int num_ double *o_samples_sum_score, int *o_num_samples) { int jump = (SAMPLE_JUMP % width) ? SAMPLE_JUMP : SAMPLE_JUMP - 1; - PIXEL *cur_pix = lines + width / 2; + int cur_x = width / 2; + PIXEL *cur_pix = lines + cur_x; PIXEL *bottom_pix; PIXEL *last_line = lines + (num_lines - 1) * width; int num_samples = 0; @@ -131,13 +132,17 @@ static void FNAME(compute_lines_gradual_score)(PIXEL *lines, int width, int num_ } while (cur_pix < last_line) { - if ((cur_pix + 1 - lines) % width == 0) { // last pixel in the row + if (cur_x + 1 == width) { // last pixel in the row cur_pix--; // jump is bigger than 1 so we will not enter endless loop + cur_x--; } bottom_pix = cur_pix + width; samples_sum_score += FNAME(pixels_square_score)(cur_pix, bottom_pix); num_samples++; cur_pix += jump; + cur_x += jump; + while (cur_x >= width) + cur_x -= width; } (*o_samples_sum_score) = samples_sum_score; |