Skip to content

Commit

Permalink
possible performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Feb 5, 2022
1 parent e5ab86b commit 1e04814
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 42 deletions.
14 changes: 8 additions & 6 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -1477,12 +1477,12 @@ am__magick_libMagickCore_@MAGICK_MAJOR_VERSION@_@MAGICK_ABI_SUFFIX@_la_SOURCES_D
magick/image.c magick/image.h magick/image-private.h \
magick/image-view.c magick/image-view.h magick/layer.c \
magick/layer.h magick/list.c magick/list.h magick/locale.c \
magick/locale_.h magick/log.c magick/log.h magick/mac.h \
magick/magic.c magick/magic.h magick/magick.c \
magick/magick-baseconfig.h magick/magick-config.h \
magick/magick-type.h magick/magick.h magick/matrix.c \
magick/matrix.h magick/memory.c magick/memory_.h \
magick/memory-private.h magick/methods.h \
magick/locale_.h magick/locale-private.h magick/log.c \
magick/log.h magick/mac.h magick/magic.c magick/magic.h \
magick/magick.c magick/magick-baseconfig.h \
magick/magick-config.h magick/magick-type.h magick/magick.h \
magick/matrix.c magick/matrix.h magick/memory.c \
magick/memory_.h magick/memory-private.h magick/methods.h \
magick/method-attribute.h magick/mime.c magick/mime.h \
magick/module.c magick/module.h magick/monitor.c \
magick/monitor.h magick/monitor-private.h magick/montage.c \
Expand Down Expand Up @@ -4784,6 +4784,7 @@ MAGICK_BASE_SRCS = \
magick/list.h \
magick/locale.c \
magick/locale_.h \
magick/locale-private.h \
magick/log.c \
magick/log.h \
magick/mac.h \
Expand Down Expand Up @@ -5044,6 +5045,7 @@ MAGICK_NOINST_HDRS = \
magick/fx-private.h \
magick/gem-private.h \
magick/image-private.h \
magick/locale-private.h \
magick/mac.h \
magick/memory-private.h \
magick/mime-private.h \
Expand Down
3 changes: 2 additions & 1 deletion coders/fits.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/locale-private.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
Expand Down Expand Up @@ -332,7 +333,7 @@ static Image *ReadFITSImage(const ImageInfo *image_info,
{
if (isspace((int) ((unsigned char) keyword[i])) != 0)
break;
keyword[i]=LocaleLowercase((int) ((unsigned char) keyword[i]));
keyword[i]=LocaleToLowercase((int) ((unsigned char) keyword[i]));
}
keyword[i]='\0';
count=ReadBlob(image,72,(unsigned char *) value);
Expand Down
3 changes: 2 additions & 1 deletion coders/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/locale-private.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/monitor.h"
Expand Down Expand Up @@ -1128,7 +1129,7 @@ static MagickBooleanType EncodeImageAttributes(Image *image,FILE *file)
if (channel_statistics == (ChannelStatistics *) NULL)
return(MagickFalse);
(void) CopyMagickString(target,locate,MaxTextExtent);
*target=(char) LocaleUppercase((int) ((unsigned char) *target));
*target=(char) LocaleToUppercase((int) ((unsigned char) *target));
(void) FormatLocaleFile(file," \"channel%s\": {\n",target);
if (image->matte != MagickFalse)
(void) PrintChannelLocations(file,image,AlphaChannel,"alpha",
Expand Down
7 changes: 4 additions & 3 deletions coders/meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/locale-private.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
Expand Down Expand Up @@ -177,10 +178,10 @@ static int stringnicmp(const char *p,const char *q,size_t n)
break;
i=(*p);
if (islower((int) ((unsigned char) i)) != 0)
i=LocaleUppercase(i);
i=LocaleToUppercase(i);
j=(*q);
if (islower((int) ((unsigned char) j)) != 0)
j=LocaleUppercase(j);
j=LocaleToUppercase(j);
if (i != j)
break;
n--;
Expand All @@ -189,7 +190,7 @@ static int stringnicmp(const char *p,const char *q,size_t n)
p++;
q++;
}
return(LocaleUppercase((int) *p)-LocaleUppercase((int) *q));
return(LocaleToUppercase((int) *p)-LocaleToUppercase((int) *q));
}

static size_t convertHTMLcodes(char *s)
Expand Down
2 changes: 1 addition & 1 deletion coders/psd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ static MagickBooleanType CheckPSDChannels(const Image *image,
return(MagickFalse);
}

static void CheckMergedImageAlpha(const PSDInfo *psd_info,Image *image)
static inline void CheckMergedImageAlpha(const PSDInfo *psd_info,Image *image)
{
/*
The number of layers cannot be used to determine if the merged image
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -4551,7 +4551,7 @@ MAGICK_PATCHLEVEL_VERSION=39

MAGICK_VERSION=6.9.12-39

MAGICK_GIT_REVISION=17025:b5bb28a0c:20220205
MAGICK_GIT_REVISION=17026:e5ab86b9f:20220205


# Substitute library versioning
Expand Down
2 changes: 2 additions & 0 deletions magick/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ MAGICK_BASE_SRCS = \
magick/list.h \
magick/locale.c \
magick/locale_.h \
magick/locale-private.h \
magick/log.c \
magick/log.h \
magick/mac.h \
Expand Down Expand Up @@ -438,6 +439,7 @@ MAGICK_NOINST_HDRS = \
magick/fx-private.h \
magick/gem-private.h \
magick/image-private.h \
magick/locale-private.h \
magick/mac.h \
magick/memory-private.h \
magick/mime-private.h \
Expand Down
3 changes: 2 additions & 1 deletion magick/animate.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "magick/image-private.h"
#include "magick/layer.h"
#include "magick/list.h"
#include "magick/locale-private.h"
#include "magick/log.h"
#include "magick/image.h"
#include "magick/memory_.h"
Expand Down Expand Up @@ -1567,7 +1568,7 @@ MagickExport Image *XAnimateImages(Display *display,
resource_info,&windows->context);
(void) CloneString(&class_hints->res_name,resource_info->client_name);
(void) CloneString(&class_hints->res_class,resource_info->client_name);
class_hints->res_class[0]=(char) LocaleUppercase((int)
class_hints->res_class[0]=(char) LocaleToUppercase((int)
class_hints->res_class[0]);
manager_hints->flags=InputHint | StateHint;
manager_hints->input=MagickFalse;
Expand Down
3 changes: 2 additions & 1 deletion magick/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/locale-private.h"
#include "magick/log.h"
#include "magick/magick.h"
#include "magick/memory_.h"
Expand Down Expand Up @@ -14484,7 +14485,7 @@ MagickExport Image *XDisplayImage(Display *display,XResourceInfo *resource_info,
resource_info,&windows->context);
(void) CloneString(&class_hints->res_name,resource_info->client_name);
(void) CloneString(&class_hints->res_class,resource_info->client_name);
class_hints->res_class[0]=(char) LocaleUppercase((int)
class_hints->res_class[0]=(char) LocaleToUppercase((int)
class_hints->res_class[0]);
manager_hints->flags=InputHint | StateHint;
manager_hints->input=MagickFalse;
Expand Down
51 changes: 51 additions & 0 deletions magick/locale-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright 1999-2021 ImageMagick Studio LLC, a non-profit organization
dedicated to making software imaging solutions freely available.
You may not use this file except in compliance with the License. You may
obtain a copy of the License at
https://imagemagick.org/script/license.php
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
MagickCore private locale methods.
*/
#ifndef MAGICKCORE_LOCALE_PRIVATE_H
#define MAGICKCORE_LOCALE_PRIVATE_H

#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif

static inline int LocaleToLowercase(const int c)
{
if ((c == EOF) || (c != (unsigned char) c))
return(c);
#if defined(MAGICKCORE_LOCALE_SUPPORT)
if (c_locale != (locale_t) NULL)
return(tolower_l((int) ((unsigned char) c),c_locale));
#endif
return(tolower((int) ((unsigned char) c)));
}

static inline int LocaleToUppercase(const int c)
{
if ((c == EOF) || (c != (unsigned char) c))
return(c);
#if defined(MAGICKCORE_LOCALE_SUPPORT)
if (c_locale != (locale_t) NULL)
return(toupper_l((int) ((unsigned char) c),c_locale));
#endif
return(toupper((int) ((unsigned char) c)));
}

#if defined(__cplusplus) || defined(c_plusplus)
}
#endif

#endif
29 changes: 9 additions & 20 deletions magick/locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "magick/hashmap.h"
#include "magick/image-private.h"
#include "magick/locale_.h"
#include "magick/locale-private.h"
#include "magick/log.h"
#include "magick/memory_.h"
#include "magick/nt-base-private.h"
Expand Down Expand Up @@ -1494,7 +1495,7 @@ MagickExport void LocaleLower(char *string)

assert(string != (char *) NULL);
for (q=string; *q != '\0'; q++)
*q=(char) LocaleLowercase((int) *q);
*q=(char) LocaleToLowercase((int) *q);
}

/*
Expand All @@ -1508,11 +1509,11 @@ MagickExport void LocaleLower(char *string)
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% LocaleLowercase() convert to uppercase.
% LocaleLowercase() converts the character to lowercase.
%
% The format of the LocaleLowercase method is:
%
% void LocaleLowercase(const int c)
% int LocaleLowercase(const int c)
%
% A description of each parameter follows:
%
Expand All @@ -1521,13 +1522,7 @@ MagickExport void LocaleLower(char *string)
*/
MagickExport int LocaleLowercase(const int c)
{
if ((c == EOF) || (c != (unsigned char) c))
return(c);
#if defined(MAGICKCORE_LOCALE_SUPPORT)
if (c_locale != (locale_t) NULL)
return(tolower_l((int) ((unsigned char) c),c_locale));
#endif
return(tolower((int) ((unsigned char) c)));
return(LocaleToLowercase(c));
}

/*
Expand Down Expand Up @@ -1634,7 +1629,7 @@ MagickExport void LocaleUpper(char *string)

assert(string != (char *) NULL);
for (q=string; *q != '\0'; q++)
*q=(char) LocaleUppercase((int) *q);
*q=(char) LocaleToUppercase((int) *q);
}

/*
Expand All @@ -1648,11 +1643,11 @@ MagickExport void LocaleUpper(char *string)
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% LocaleUppercase() convert to uppercase.
% LocaleUppercase() converts the character to uppercase.
%
% The format of the LocaleUppercase method is:
%
% void LocaleUppercase(const int c)
% int LocaleUppercase(const int c)
%
% A description of each parameter follows:
%
Expand All @@ -1661,13 +1656,7 @@ MagickExport void LocaleUpper(char *string)
*/
MagickExport int LocaleUppercase(const int c)
{
if (c == EOF)
return(c);
#if defined(MAGICKCORE_LOCALE_SUPPORT)
if (c_locale != (locale_t) NULL)
return(toupper_l((int) ((unsigned char) c),c_locale));
#endif
return(toupper((int) ((unsigned char) c)));
return(LocaleToUppercase(c));
}

/*
Expand Down
4 changes: 2 additions & 2 deletions magick/methods.h
Original file line number Diff line number Diff line change
Expand Up @@ -851,10 +851,10 @@ extern "C" {
#define LocaleCompare PrependMagickMethod(LocaleCompare)
#define LocaleComponentGenesis PrependMagickMethod(LocaleComponentGenesis)
#define LocaleComponentTerminus PrependMagickMethod(LocaleComponentTerminus)
#define LocaleLowercase PrependMagickMethod(LocaleLowercase)
#define LocaleToLowercase PrependMagickMethod(LocaleToLowercase)
#define LocaleLower PrependMagickMethod(LocaleLower)
#define LocaleNCompare PrependMagickMethod(LocaleNCompare)
#define LocaleUppercase PrependMagickMethod(LocaleUppercase)
#define LocaleToUppercase PrependMagickMethod(LocaleToUppercase)
#define LocaleUpper PrependMagickMethod(LocaleUpper)
#define LockSemaphoreInfo PrependMagickMethod(LockSemaphoreInfo)
#define LogComponentGenesis PrependMagickMethod(LogComponentGenesis)
Expand Down
2 changes: 1 addition & 1 deletion magick/nt-feature.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ MagickExport MagickBooleanType NTIsMagickConflict(const char *magick)
if (strlen(magick) > 1)
return(MagickFalse);
status=(GetLogicalDrives() & (1 <<
((LocaleUppercase((int) (*magick)))-'A'))) != 0 ? MagickTrue : MagickFalse;
((LocaleToUppercase((int) (*magick)))-'A'))) != 0 ? MagickTrue : MagickFalse;
return(status);
}

Expand Down
7 changes: 4 additions & 3 deletions magick/token.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/locale-private.h"
#include "magick/memory_.h"
#include "magick/string_.h"
#include "magick/string-private.h"
Expand Down Expand Up @@ -550,7 +551,7 @@ MagickExport MagickBooleanType GlobExpression(
{
if (case_insensitive != MagickFalse)
{
if (LocaleLowercase((int) GetUTFCode(expression)) != LocaleLowercase((int) GetUTFCode(pattern)))
if (LocaleToLowercase((int) GetUTFCode(expression)) != LocaleToLowercase((int) GetUTFCode(pattern)))
{
done=MagickTrue;
break;
Expand Down Expand Up @@ -864,12 +865,12 @@ static void StoreToken(TokenInfo *token_info,char *string,
{
case 1:
{
string[i]=(char) LocaleUppercase(c);
string[i]=(char) LocaleToUppercase(c);
break;
}
case 2:
{
string[i]=(char) LocaleLowercase(c);
string[i]=(char) LocaleToLowercase(c);
break;
}
default:
Expand Down
2 changes: 1 addition & 1 deletion magick/vms.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ struct dirent *readdir(DIR *directory)
buffer[sizeof(buffer)-1]='\0';
for (p=buffer; *p; p++)
if (isupper((int) ((unsigned char) *p)))
*p=LocaleLowercase(*p);
*p=LocaleToLowercase(*p);
/*
Skip any directory component and just copy the name.
*/
Expand Down

0 comments on commit 1e04814

Please sign in to comment.