From 6ca9a907b8e0497e1888a27d52da4021ce40bf9d Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 13 Jan 2016 20:32:23 +0000 Subject: [PATCH] reorder load tests and a slight memory saving on ifthenelse --- ChangeLog | 2 ++ libvips/conversion/ifthenelse.c | 11 +++++++++-- libvips/foreign/analyzeload.c | 4 ++++ libvips/foreign/csvload.c | 4 ++++ libvips/foreign/fitsload.c | 4 ++++ libvips/foreign/jpegload.c | 4 ++++ libvips/foreign/matrixload.c | 4 ++++ libvips/foreign/openexrload.c | 4 ++++ libvips/foreign/pngload.c | 4 ++++ libvips/foreign/ppmload.c | 4 ++++ libvips/foreign/radload.c | 4 ++++ libvips/foreign/tiffload.c | 4 ++++ libvips/foreign/vipsload.c | 4 ++++ libvips/foreign/webpload.c | 5 +++++ 14 files changed, 60 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1db9bb66..7954265a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 12/1/16 started 8.2.2 - changes to ease compiling C++ binding with MSVC +- reorder file tests to put slow loaders last +- ifthenelse needs less C stack during eval 1/1/16 started 8.2.1 - add a compat stub, thanks Benjamin diff --git a/libvips/conversion/ifthenelse.c b/libvips/conversion/ifthenelse.c index 0304a4fa..1170cca6 100644 --- a/libvips/conversion/ifthenelse.c +++ b/libvips/conversion/ifthenelse.c @@ -437,8 +437,15 @@ vips_ifthenelse_build( VipsObject *object ) /* Condition is cast to uchar, then/else to a common type. */ - if( vips_cast( size[2], &format[2], VIPS_FORMAT_UCHAR, NULL ) ) - return( -1 ); + if( size[2]->BandFmt != VIPS_FORMAT_UCHAR ) { + if( vips_cast( size[2], &format[2], VIPS_FORMAT_UCHAR, NULL ) ) + return( -1 ); + } + else { + format[2] = size[2]; + g_object_ref( format[2] ); + } + if( vips__formatalike_vec( size, format, 2 ) ) return( -1 ); diff --git a/libvips/foreign/analyzeload.c b/libvips/foreign/analyzeload.c index 37cc68d7..0bb1c6cd 100644 --- a/libvips/foreign/analyzeload.c +++ b/libvips/foreign/analyzeload.c @@ -118,6 +118,10 @@ vips_foreign_load_analyze_class_init( VipsForeignLoadAnalyzeClass *class ) foreign_class->suffs = vips_foreign_analyze_suffs; + /* is_a() is not that quick ... lower the priority. + */ + foreign_class->priority = -50; + load_class->is_a = vips__isanalyze; load_class->get_flags_filename = vips_foreign_load_analyze_get_flags_filename; diff --git a/libvips/foreign/csvload.c b/libvips/foreign/csvload.c index e51949fe..ad1b3646 100644 --- a/libvips/foreign/csvload.c +++ b/libvips/foreign/csvload.c @@ -125,6 +125,10 @@ vips_foreign_load_csv_class_init( VipsForeignLoadCsvClass *class ) foreign_class->suffs = vips__foreign_csv_suffs; + /* is_a() is not that quick ... lower the priority. + */ + foreign_class->priority = -50; + load_class->get_flags_filename = vips_foreign_load_csv_get_flags_filename; load_class->get_flags = vips_foreign_load_csv_get_flags; diff --git a/libvips/foreign/fitsload.c b/libvips/foreign/fitsload.c index 678d1947..179e497c 100644 --- a/libvips/foreign/fitsload.c +++ b/libvips/foreign/fitsload.c @@ -109,6 +109,10 @@ vips_foreign_load_fits_class_init( VipsForeignLoadFitsClass *class ) object_class->nickname = "fitsload"; object_class->description = _( "load a FITS image" ); + /* is_a() is not that quick ... lower the priority. + */ + foreign_class->priority = -50; + foreign_class->suffs = vips__fits_suffs; load_class->is_a = vips__fits_isfits; diff --git a/libvips/foreign/jpegload.c b/libvips/foreign/jpegload.c index 3a5fa031..2e81077e 100644 --- a/libvips/foreign/jpegload.c +++ b/libvips/foreign/jpegload.c @@ -240,6 +240,10 @@ vips_foreign_load_jpeg_file_class_init( VipsForeignLoadJpegFileClass *class ) foreign_class->suffs = jpeg_suffs; + /* We are fast at is_a(), so high priority. + */ + foreign_class->priority = 200; + load_class->get_flags_filename = vips_foreign_load_jpeg_file_get_flags_filename; load_class->is_a = vips_foreign_load_jpeg_file_is_a; diff --git a/libvips/foreign/matrixload.c b/libvips/foreign/matrixload.c index 254be289..24742d48 100644 --- a/libvips/foreign/matrixload.c +++ b/libvips/foreign/matrixload.c @@ -138,6 +138,10 @@ vips_foreign_load_matrix_class_init( VipsForeignLoadMatrixClass *class ) foreign_class->suffs = vips__foreign_matrix_suffs; + /* is_a() is not that quick ... lower the priority. + */ + foreign_class->priority = -50; + load_class->is_a = vips__matrix_ismatrix; load_class->get_flags_filename = vips_foreign_load_matrix_get_flags_filename; diff --git a/libvips/foreign/openexrload.c b/libvips/foreign/openexrload.c index 94f147d7..cc0a432b 100644 --- a/libvips/foreign/openexrload.c +++ b/libvips/foreign/openexrload.c @@ -129,6 +129,10 @@ vips_foreign_load_openexr_class_init( VipsForeignLoadOpenexrClass *class ) foreign_class->suffs = vips_foreign_openexr_suffs; + /* We are fast at is_a(), so high priority. + */ + foreign_class->priority = 200; + load_class->is_a = vips__openexr_isexr; load_class->get_flags_filename = vips_foreign_load_openexr_get_flags_filename; diff --git a/libvips/foreign/pngload.c b/libvips/foreign/pngload.c index bd855d65..63f5ee46 100644 --- a/libvips/foreign/pngload.c +++ b/libvips/foreign/pngload.c @@ -129,6 +129,10 @@ vips_foreign_load_png_class_init( VipsForeignLoadPngClass *class ) foreign_class->suffs = vips__png_suffs; + /* We are fast at is_a(), so high priority. + */ + foreign_class->priority = 200; + load_class->is_a = vips__png_ispng; load_class->get_flags_filename = vips_foreign_load_png_get_flags_filename; diff --git a/libvips/foreign/ppmload.c b/libvips/foreign/ppmload.c index 81accecc..55a5abaf 100644 --- a/libvips/foreign/ppmload.c +++ b/libvips/foreign/ppmload.c @@ -118,6 +118,10 @@ vips_foreign_load_ppm_class_init( VipsForeignLoadPpmClass *class ) foreign_class->suffs = vips__ppm_suffs; + /* We are fast at is_a(), so high priority. + */ + foreign_class->priority = 200; + load_class->is_a = vips__ppm_isppm; load_class->get_flags_filename = vips_foreign_load_ppm_get_flags_filename; diff --git a/libvips/foreign/radload.c b/libvips/foreign/radload.c index f199fc14..66ab5d55 100644 --- a/libvips/foreign/radload.c +++ b/libvips/foreign/radload.c @@ -121,6 +121,10 @@ vips_foreign_load_rad_class_init( VipsForeignLoadRadClass *class ) foreign_class->suffs = vips__rad_suffs; + /* is_a() is not that quick ... lower the priority. + */ + foreign_class->priority = -50; + load_class->is_a = vips__rad_israd; load_class->get_flags_filename = vips_foreign_load_rad_get_flags_filename; diff --git a/libvips/foreign/tiffload.c b/libvips/foreign/tiffload.c index c453d1a3..853e63f0 100644 --- a/libvips/foreign/tiffload.c +++ b/libvips/foreign/tiffload.c @@ -179,6 +179,10 @@ vips_foreign_load_tiff_file_class_init( VipsForeignLoadTiffFileClass *class ) object_class->nickname = "tiffload"; object_class->description = _( "load tiff from file" ); + /* We are fast, but must test after openslideload. + */ + foreign_class->priority = 50; + foreign_class->suffs = vips__foreign_tiff_suffs; load_class->is_a = vips__istiff; diff --git a/libvips/foreign/vipsload.c b/libvips/foreign/vipsload.c index 41ac40b3..317014a3 100644 --- a/libvips/foreign/vipsload.c +++ b/libvips/foreign/vipsload.c @@ -123,6 +123,10 @@ vips_foreign_load_vips_class_init( VipsForeignLoadVipsClass *class ) foreign_class->suffs = vips__suffs; + /* We are fast at is_a(), so high priority. + */ + foreign_class->priority = 200; + load_class->is_a = vips_foreign_load_vips_is_a; load_class->get_flags = vips_foreign_load_vips_get_flags; load_class->get_flags_filename = diff --git a/libvips/foreign/webpload.c b/libvips/foreign/webpload.c index 51ed3db6..cb7edcb8 100644 --- a/libvips/foreign/webpload.c +++ b/libvips/foreign/webpload.c @@ -229,6 +229,7 @@ vips_foreign_load_webp_buffer_class_init( { GObjectClass *gobject_class = G_OBJECT_CLASS( class ); VipsObjectClass *object_class = (VipsObjectClass *) class; + VipsForeignClass *foreign_class = (VipsForeignClass *) class; VipsForeignLoadClass *load_class = (VipsForeignLoadClass *) class; gobject_class->set_property = vips_object_set_property; @@ -237,6 +238,10 @@ vips_foreign_load_webp_buffer_class_init( object_class->nickname = "webpload_buffer"; object_class->description = _( "load webp from buffer" ); + /* is_a() is not that quick ... lower the priority. + */ + foreign_class->priority = -50; + load_class->is_a_buffer = vips__iswebp_buffer; load_class->header = vips_foreign_load_webp_buffer_header; load_class->load = vips_foreign_load_webp_buffer_load;