tiny optimisations

This commit is contained in:
John Cupitt 2017-10-16 20:55:58 +01:00
parent 99f02aeff1
commit a8bbe05596
2 changed files with 20 additions and 7 deletions

View File

@ -1111,12 +1111,23 @@ vips_region_copy( VipsRegion *reg, VipsRegion *dest, VipsRect *r, int x, int y )
VIPS_IMAGE_SIZEOF_PEL( dest->im ) );
#endif /*DEBUG*/
for( z = 0; z < r->height; z++ ) {
memcpy( q, p, len );
/* Copy the scanlines.
*
* Special case: if the two sets of scanlines are end-to-end (this
* happens if we are copying complete regions) we can do a single
* memcpy() for the whole thing. This is a little faster since we
* won't have to do unaligned copies.
*/
if( len == plsk &&
len == qlsk )
memcpy( q, p, len * r->height );
else
for( z = 0; z < r->height; z++ ) {
memcpy( q, p, len );
p += plsk;
q += qlsk;
}
p += plsk;
q += qlsk;
}
}
/* Generate area @target in @to using pixels in @from.

View File

@ -438,8 +438,10 @@ reduce_sum( const T * restrict in, int stride, const IT * restrict c, int n )
IT sum;
sum = 0;
for( int i = 0; i < n; i++ )
sum += c[i] * in[i * stride];
for( int i = 0; i < n; i++ ) {
sum += c[i] * in[0];
in += stride;
}
return( sum );
}