Skip to content

Commit f342afa

Browse files
committed
Merge branch 'nk/ctype-for-perf' into maint
* nk/ctype-for-perf: ctype: implement islower/isupper macro ctype.c only wants git-compat-util.h
2 parents e6d88ca + 43ccdf5 commit f342afa

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

ctype.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* No surprises, and works with signed and unsigned chars.
55
*/
6-
#include "cache.h"
6+
#include "git-compat-util.h"
77

88
enum {
99
S = GIT_SPACE,

git-compat-util.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ static inline int has_extension(const char *filename, const char *ext)
463463
#undef isdigit
464464
#undef isalpha
465465
#undef isalnum
466+
#undef islower
467+
#undef isupper
466468
#undef tolower
467469
#undef toupper
468470
extern unsigned char sane_ctype[256];
@@ -478,6 +480,8 @@ extern unsigned char sane_ctype[256];
478480
#define isdigit(x) sane_istest(x,GIT_DIGIT)
479481
#define isalpha(x) sane_istest(x,GIT_ALPHA)
480482
#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
483+
#define islower(x) sane_iscase(x, 1)
484+
#define isupper(x) sane_iscase(x, 0)
481485
#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
482486
#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)
483487
#define tolower(x) sane_case((unsigned char)(x), 0x20)
@@ -491,6 +495,17 @@ static inline int sane_case(int x, int high)
491495
return x;
492496
}
493497

498+
static inline int sane_iscase(int x, int is_lower)
499+
{
500+
if (!sane_istest(x, GIT_ALPHA))
501+
return 0;
502+
503+
if (is_lower)
504+
return (x & 0x20) != 0;
505+
else
506+
return (x & 0x20) == 0;
507+
}
508+
494509
static inline int strtoul_ui(char const *s, int base, unsigned int *result)
495510
{
496511
unsigned long ul;

0 commit comments

Comments
 (0)