add VIPS_ONCE and use it everywhere
Lovell's idea: save the function call in the most common case
This commit is contained in:
parent
8806e7039e
commit
f9f717a843
@ -171,8 +171,7 @@ vips_col_make_tables_RGB_8( void )
|
||||
{
|
||||
static GOnce once = G_ONCE_INIT;
|
||||
|
||||
if( G_UNLIKELY( once.status != G_ONCE_STATUS_READY ) )
|
||||
(void) g_once( &once, calcul_tables_8, NULL );
|
||||
VIPS_ONCE( &once, calcul_tables_8, NULL );
|
||||
}
|
||||
|
||||
int
|
||||
@ -196,8 +195,7 @@ vips_col_make_tables_RGB_16( void )
|
||||
{
|
||||
static GOnce once = G_ONCE_INIT;
|
||||
|
||||
if( G_UNLIKELY( once.status != G_ONCE_STATUS_READY ) )
|
||||
(void) g_once( &once, calcul_tables_16, NULL );
|
||||
VIPS_ONCE( &once, calcul_tables_16, NULL );
|
||||
}
|
||||
|
||||
int
|
||||
@ -448,7 +446,7 @@ vips_col_make_tables_LabQ2sRGB( void )
|
||||
{
|
||||
static GOnce once = G_ONCE_INIT;
|
||||
|
||||
(void) g_once( &once, build_tables, NULL );
|
||||
VIPS_ONCE( &once, build_tables, NULL );
|
||||
}
|
||||
|
||||
/* Process a buffer of data.
|
||||
|
@ -228,7 +228,7 @@ vips_col_make_tables_CMC( void )
|
||||
{
|
||||
static GOnce once = G_ONCE_INIT;
|
||||
|
||||
(void) g_once( &once, tables_init, NULL );
|
||||
VIPS_ONCE( &once, tables_init, NULL );
|
||||
}
|
||||
|
||||
/* Process a buffer of data.
|
||||
|
@ -120,7 +120,7 @@ vips_XYZ2Lab_line( VipsColour *colour, VipsPel *out, VipsPel **in, int width )
|
||||
|
||||
int x;
|
||||
|
||||
(void) g_once( &once, table_init, NULL );
|
||||
VIPS_ONCE( &once, table_init, NULL );
|
||||
|
||||
for( x = 0; x < width; x++ ) {
|
||||
float nX, nY, nZ;
|
||||
|
@ -284,7 +284,7 @@ vips_perlin_class_init( VipsPerlinClass *class )
|
||||
|
||||
static GOnce once = G_ONCE_INIT;
|
||||
|
||||
(void) g_once( &once, vips_perlin_make_tables, NULL );
|
||||
VIPS_ONCE( &once, vips_perlin_make_tables, NULL );
|
||||
|
||||
gobject_class->set_property = vips_object_set_property;
|
||||
gobject_class->get_property = vips_object_get_property;
|
||||
|
@ -408,7 +408,7 @@ vips_text_class_init( VipsTextClass *class )
|
||||
|
||||
static GOnce once = G_ONCE_INIT;
|
||||
|
||||
(void) g_once( &once, vips_text_make_lock, NULL );
|
||||
VIPS_ONCE( &once, vips_text_make_lock, NULL );
|
||||
|
||||
gobject_class->dispose = vips_text_dispose;
|
||||
gobject_class->set_property = vips_object_set_property;
|
||||
|
@ -293,7 +293,7 @@ vips_foreign_load_magick7_genesis( void )
|
||||
{
|
||||
static GOnce once = G_ONCE_INIT;
|
||||
|
||||
(void) g_once( &once, vips_foreign_load_magick7_genesis_cb, NULL );
|
||||
VIPS_ONCE( &once, vips_foreign_load_magick7_genesis_cb, NULL );
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -86,6 +86,14 @@ extern "C" {
|
||||
#define VIPS_FMIN( A, B ) VIPS_MIN( A, B )
|
||||
#endif
|
||||
|
||||
/* Testing status before the function call saves a lot of time.
|
||||
*/
|
||||
#define VIPS_ONCE( ONCE, FUNC, CLIENT ) \
|
||||
G_STMT_START { \
|
||||
if( G_UNLIKELY( (ONCE)->status != G_ONCE_STATUS_READY ) ) \
|
||||
(void) g_once( ONCE, FUNC, CLIENT ); \
|
||||
} G_STMT_END
|
||||
|
||||
/* VIPS_RINT() does "bankers rounding", it rounds to the nerarest even integer.
|
||||
* For things like image geometry, we want strict nearest int.
|
||||
*
|
||||
|
@ -462,7 +462,7 @@ vips__cache_init( void )
|
||||
{
|
||||
static GOnce once = G_ONCE_INIT;
|
||||
|
||||
g_once( &once, (GThreadFunc) vips__cache_once_init, NULL );
|
||||
VIPS_ONCE( &once, (GThreadFunc) vips__cache_once_init, NULL );
|
||||
}
|
||||
|
||||
static void *
|
||||
|
@ -245,7 +245,7 @@ vips__thread_profile_attach( const char *thread_name )
|
||||
|
||||
VipsThreadProfile *profile;
|
||||
|
||||
g_once( &once, (GThreadFunc) vips__thread_profile_init, NULL );
|
||||
VIPS_ONCE( &once, (GThreadFunc) vips__thread_profile_init, NULL );
|
||||
|
||||
VIPS_DEBUG_MSG( "vips__thread_profile_attach: %s\n", thread_name );
|
||||
|
||||
|
@ -273,7 +273,7 @@ vips_tracked_init( void )
|
||||
{
|
||||
static GOnce vips_tracked_once = G_ONCE_INIT;
|
||||
|
||||
g_once( &vips_tracked_once,
|
||||
VIPS_ONCE( &vips_tracked_once,
|
||||
(GThreadFunc) vips_tracked_init_mutex, NULL );
|
||||
}
|
||||
|
||||
|
@ -2814,7 +2814,7 @@ vips_type_find( const char *basename, const char *nickname )
|
||||
GType base;
|
||||
GType type;
|
||||
|
||||
g_once( &once, (GThreadFunc) vips_class_build_hash, NULL );
|
||||
VIPS_ONCE( &once, (GThreadFunc) vips_class_build_hash, NULL );
|
||||
|
||||
hit = (NicknameGType *)
|
||||
g_hash_table_lookup( vips__object_nickname_table,
|
||||
|
@ -1081,7 +1081,7 @@ vips_sink_screen( VipsImage *in, VipsImage *out, VipsImage *mask,
|
||||
|
||||
Render *render;
|
||||
|
||||
g_once( &once, (GThreadFunc) vips_sink_screen_init, NULL );
|
||||
VIPS_ONCE( &once, (GThreadFunc) vips_sink_screen_init, NULL );
|
||||
|
||||
if( tile_width <= 0 || tile_height <= 0 ||
|
||||
max_tiles < -1 ) {
|
||||
|
Loading…
Reference in New Issue
Block a user