aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-02-05 19:29:59 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-02-05 19:29:59 +0530
commitb716cac0c9bbde4c796365d790ffd5f1149edac6 (patch)
tree7d0d2ac485529946242f43b0aad89bc309ca4c80 /src
parent4016eaeeb37dfd9f396c4df1c93e52c6aca3cd1e (diff)
downloadnnn-b716cac0c9bbde4c796365d790ffd5f1149edac6.tar.gz
Use a macro for digit check
Diffstat (limited to 'src')
-rw-r--r--src/nnn.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/nnn.c b/src/nnn.c
index e2779bb..c4b6e28 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -218,6 +218,8 @@ disabledbg()
#define setdirwatch() (cfg.filtermode ? (presel = FILTER) : (dir_changed = TRUE))
/* We don't care about the return value from strcmp() */
#define xstrcmp(a, b) (*(a) != *(b) ? -1 : strcmp((a), (b)))
+/* A faster version of xisdigit */
+#define xisdigit(c) ((unsigned int) (c) - '0' <= 9)
#ifdef LINUX_INOTIFY
#define EVENT_SIZE (sizeof(struct inotify_event))
@@ -751,7 +753,7 @@ static uint xatoi(const char *str)
if (!str)
return 0;
- while (*str >= '0' && *str <= '9')
+ while (xisdigit(*str))
{
val = val * 10 + (*str - '0');
++str;
@@ -1126,7 +1128,7 @@ static int xstricmp(const char * const s1, const char * const s2)
++c2;
}
- if ((*c1 >= '0' && *c1 <= '9') && (*c2 >= '0' && *c2 <= '9')) {
+ if (xisdigit(*c1) && xisdigit(*c2)) {
while (*c1 == '0')
++c1;
m1 = c1;
@@ -1135,14 +1137,14 @@ static int xstricmp(const char * const s1, const char * const s2)
++c2;
m2 = c2;
- while (*c1 >= '0' && *c1 <= '9') {
+ while (xisdigit(*c1)) {
++count1;
++c1;
}
while (isspace(*c1))
++c1;
- while (*c2 >= '0' && *c2 <= '9') {
+ while (xisdigit(*c2)) {
++count2;
++c2;
}
@@ -1177,7 +1179,7 @@ static int xstricmp(const char * const s1, const char * const s2)
/* Return the integer value of a char representing HEX */
static char xchartohex(char c)
{
- if (c >= '0' && c <= '9')
+ if (xisdigit(c))
return c - '0';
c = TOUPPER(c);