From: Cristy Date: Sat, 16 Sep 2017 14:13:23 +0000 (-0400) Subject: Slight performance increase by reducing semaphore calls X-Git-Tag: 7.0.7-3~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d8b1f1382058644509256623426cae0cdf70efd;p=imagemagick Slight performance increase by reducing semaphore calls --- diff --git a/MagickCore/coder.c b/MagickCore/coder.c index bf8f847ef..0c647d5e7 100644 --- a/MagickCore/coder.c +++ b/MagickCore/coder.c @@ -472,23 +472,12 @@ MagickPrivate void CoderComponentTerminus(void) MagickExport const CoderInfo *GetCoderInfo(const char *name, ExceptionInfo *exception) { - const CoderInfo - *coder_info; - assert(exception != (ExceptionInfo *) NULL); if (IsCoderTreeInstantiated(exception) == MagickFalse) return((const CoderInfo *) NULL); - LockSemaphoreInfo(coder_semaphore); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) - { - ResetSplayTreeIterator(coder_cache); - coder_info=(const CoderInfo *) GetNextValueInSplayTree(coder_cache); - UnlockSemaphoreInfo(coder_semaphore); - return(coder_info); - } - coder_info=(const CoderInfo *) GetValueFromSplayTree(coder_cache,name); - UnlockSemaphoreInfo(coder_semaphore); - return(coder_info); + return((const CoderInfo *) GetRootValueFromSplayTree(coder_cache)); + return((const CoderInfo *) GetValueFromSplayTree(coder_cache,name)); } /* diff --git a/MagickCore/magick.c b/MagickCore/magick.c index 1c590f9ad..462e046dd 100644 --- a/MagickCore/magick.c +++ b/MagickCore/magick.c @@ -625,13 +625,7 @@ MagickExport const MagickInfo *GetMagickInfo(const char *name, } #endif if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) - { - LockSemaphoreInfo(magick_semaphore); - ResetSplayTreeIterator(magick_list); - magick_info=(const MagickInfo *) GetNextValueInSplayTree(magick_list); - UnlockSemaphoreInfo(magick_semaphore); - return(magick_info); - } + magick_info=(const MagickInfo *) GetRootValueFromSplayTree(magick_list); if (magick_info == (const MagickInfo *) NULL) magick_info=(const MagickInfo *) GetValueFromSplayTree(magick_list,name); return(magick_info); diff --git a/MagickCore/splay-tree.c b/MagickCore/splay-tree.c index 64d989fc0..5f55bea8f 100644 --- a/MagickCore/splay-tree.c +++ b/MagickCore/splay-tree.c @@ -854,6 +854,47 @@ MagickExport const void *GetNextValueInSplayTree(SplayTreeInfo *splay_tree) % % % % % % +% G e t R o o t V a l u e F r o m S p l a y T r e e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% GetRootValueFromSplayTree() gets the root value from the splay-tree. +% +% The format of the GetRootValueFromSplayTree method is: +% +% const void *GetRootValueFromSplayTree(SplayTreeInfo *splay_tree) +% +% A description of each parameter follows: +% +% o splay_tree: the splay tree. +% +% o key: the key. +% +*/ +MagickExport const void *GetRootValueFromSplayTree(SplayTreeInfo *splay_tree) +{ + const void + *value; + + assert(splay_tree != (SplayTreeInfo *) NULL); + assert(splay_tree->signature == MagickCoreSignature); + if (splay_tree->debug != MagickFalse) + (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); + LockSemaphoreInfo(splay_tree->semaphore); + value=NULL; + if (splay_tree->root != (NodeInfo *) NULL) + value=splay_tree->root->value; + UnlockSemaphoreInfo(splay_tree->semaphore); + return(value); +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % % G e t V a l u e F r o m S p l a y T r e e % % % % % diff --git a/MagickCore/splay-tree.h b/MagickCore/splay-tree.h index 222a2a5ef..860ebb00e 100644 --- a/MagickCore/splay-tree.h +++ b/MagickCore/splay-tree.h @@ -33,6 +33,7 @@ extern MagickExport MagickBooleanType extern MagickExport const void *GetNextKeyInSplayTree(SplayTreeInfo *), *GetNextValueInSplayTree(SplayTreeInfo *), + *GetRootValueFromSplayTree(SplayTreeInfo *), *GetValueFromSplayTree(SplayTreeInfo *,const void *); extern MagickExport int diff --git a/MagickCore/type.c b/MagickCore/type.c index 2b47563df..80e73ceab 100644 --- a/MagickCore/type.c +++ b/MagickCore/type.c @@ -277,23 +277,12 @@ static SplayTreeInfo *AcquireTypeCache(const char *filename, MagickExport const TypeInfo *GetTypeInfo(const char *name, ExceptionInfo *exception) { - const TypeInfo - *type_info; - assert(exception != (ExceptionInfo *) NULL); if (IsTypeTreeInstantiated(exception) == MagickFalse) return((const TypeInfo *) NULL); - LockSemaphoreInfo(type_semaphore); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) - { - ResetSplayTreeIterator(type_cache); - type_info=(const TypeInfo *) GetNextValueInSplayTree(type_cache); - UnlockSemaphoreInfo(type_semaphore); - return(type_info); - } - type_info=(const TypeInfo *) GetValueFromSplayTree(type_cache,name); - UnlockSemaphoreInfo(type_semaphore); - return(type_info); + return((const TypeInfo *) GetRootValueFromSplayTree(type_cache)); + return((const TypeInfo *) GetValueFromSplayTree(type_cache,name)); } /*