From 33d90b5e26310d1c3c01a1b041a6004a661e6a54 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 1 Mar 2019 13:01:08 +0000 Subject: [PATCH] only enable sanity checks in debug mode We had a couple of sanity checks always on. As a result, libvips could get slow for large pipelines. Move them into g_assert(). --- libvips/foreign/dzsave.c | 4 +--- libvips/iofuncs/image.c | 11 ++++------- libvips/iofuncs/region.c | 6 ------ libvips/iofuncs/reorder.c | 6 ++++-- 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/libvips/foreign/dzsave.c b/libvips/foreign/dzsave.c index 9f0d761d..943840ac 100644 --- a/libvips/foreign/dzsave.c +++ b/libvips/foreign/dzsave.c @@ -1158,9 +1158,7 @@ strip_work( VipsThreadState *state, void *a ) } } -#ifdef DEBUG - vips_object_sanity( VIPS_OBJECT( strip->image ) ); -#endif /*DEBUG*/ + g_assert( vips_object_sanity( VIPS_OBJECT( strip->image ) ) ); /* Extract relative to the strip top-left corner. */ diff --git a/libvips/iofuncs/image.c b/libvips/iofuncs/image.c index 7520f70b..2116f222 100644 --- a/libvips/iofuncs/image.c +++ b/libvips/iofuncs/image.c @@ -2918,9 +2918,8 @@ vips_image_hasalpha( VipsImage *image ) */ int vips_image_write_prepare( VipsImage *image ) -{ - if( !vips_object_sanity( VIPS_OBJECT( image ) ) ) - return( -1 ); +{ + g_assert( vips_object_sanity( VIPS_OBJECT( image ) ) ); if( image->Xsize <= 0 || image->Ysize <= 0 || @@ -3181,8 +3180,7 @@ vips_image_wio_input( VipsImage *image ) { VipsImage *t1; - if( !vips_object_sanity( VIPS_OBJECT( image ) ) ) - return( -1 ); + g_assert( vips_object_sanity( VIPS_OBJECT( image ) ) ); #ifdef DEBUG_IO printf( "vips_image_wio_input: wio input for %s\n", @@ -3406,8 +3404,7 @@ vips_image_inplace( VipsImage *image ) int vips_image_pio_input( VipsImage *image ) { - if( !vips_object_sanity( VIPS_OBJECT( image ) ) ) - return( -1 ); + g_assert( vips_object_sanity( VIPS_OBJECT( image ) ) ); #ifdef DEBUG_IO printf( "vips_image_pio_input: enabling partial input for %s\n", diff --git a/libvips/iofuncs/region.c b/libvips/iofuncs/region.c index 42f84c0c..327b95b9 100644 --- a/libvips/iofuncs/region.c +++ b/libvips/iofuncs/region.c @@ -527,12 +527,8 @@ vips_region_new( VipsImage *image ) * We can't use the property system, we need to be very threaded. */ g_object_ref( image ); - g_assert( G_OBJECT( image )->ref_count > 1 ); - -#ifdef DEBUG g_assert( vips_object_sanity( VIPS_OBJECT( image ) ) ); -#endif /*DEBUG*/ region = VIPS_REGION( g_object_new( VIPS_TYPE_REGION, NULL ) ); region->im = image; @@ -542,9 +538,7 @@ vips_region_new( VipsImage *image ) return( NULL ); } -#ifdef DEBUG g_assert( vips_object_sanity( VIPS_OBJECT( region ) ) ); -#endif /*DEBUG*/ return( region ); } diff --git a/libvips/iofuncs/reorder.c b/libvips/iofuncs/reorder.c index 30259a3e..0994a900 100644 --- a/libvips/iofuncs/reorder.c +++ b/libvips/iofuncs/reorder.c @@ -338,7 +338,8 @@ vips_reorder_prepare_many( VipsImage *image, VipsRegion **regions, VipsRect *r ) for( i = 0; i < reorder->n_inputs; i++ ) { g_assert( regions[i] ); - if( vips_region_prepare( regions[reorder->recomp_order[i]], r ) ) + if( vips_region_prepare( + regions[reorder->recomp_order[i]], r ) ) return( -1 ); } @@ -374,7 +375,8 @@ vips_reorder_margin_hint( VipsImage *image, int margin ) void vips__reorder_clear( VipsImage *image ) { - g_object_set_qdata( G_OBJECT( image ), vips__image_reorder_quark, NULL ); + g_object_set_qdata( G_OBJECT( image ), + vips__image_reorder_quark, NULL ); } void