]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl_ctype: convert to macros-only
authorDaniel Stenberg <daniel@haxx.se>
Mon, 5 Sep 2022 10:15:21 +0000 (12:15 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 6 Sep 2022 06:36:33 +0000 (08:36 +0200)
This no longer provide functions, only macros. Runs faster and produces
smaller output.

The biggest precaution this change brings:

DO NOT use post/pre-increments when passing arguments to the macros.

Closes #9429

lib/Makefile.inc
lib/curl_ctype.c [deleted file]
lib/curl_ctype.h
lib/http_chunks.c
projects/generate.bat
src/Makefile.inc
src/tool_formparse.c
tests/libtest/Makefile.inc
tests/server/Makefile.inc
winbuild/MakefileBuild.vc

index 9bd8e324bd1c155715b117f40872e6d3c3203c36..af47fe6a20f8e7bcf06fadc5c2b85034fb1c3b70 100644 (file)
@@ -110,7 +110,6 @@ LIB_CFILES =         \
   content_encoding.c \
   cookie.c           \
   curl_addrinfo.c    \
-  curl_ctype.c       \
   curl_des.c         \
   curl_endian.c      \
   curl_fnmatch.c     \
diff --git a/lib/curl_ctype.c b/lib/curl_ctype.c
deleted file mode 100644 (file)
index e1a8445..0000000
+++ /dev/null
@@ -1,132 +0,0 @@
-/***************************************************************************
- *                                  _   _ ____  _
- *  Project                     ___| | | |  _ \| |
- *                             / __| | | | |_) | |
- *                            | (__| |_| |  _ <| |___
- *                             \___|\___/|_| \_\_____|
- *
- * Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, et al.
- *
- * This software is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at https://curl.se/docs/copyright.html.
- *
- * You may opt to use, copy, modify, merge, publish, distribute and/or sell
- * copies of the Software, and permit persons to whom the Software is
- * furnished to do so, under the terms of the COPYING file.
- *
- * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
- * KIND, either express or implied.
- *
- * SPDX-License-Identifier: curl
- *
- ***************************************************************************/
-
-#include "curl_setup.h"
-
-#undef _U
-#define _U (1<<0) /* upper case */
-#undef _L
-#define _L (1<<1) /* lower case */
-#undef _N
-#define _N (1<<2) /* decimal numerical digit */
-#undef _S
-#define _S (1<<3) /* space */
-#undef _P
-#define _P (1<<4) /* punctuation */
-#undef _C
-#define _C (1<<5) /* control */
-#undef _X
-#define _X (1<<6) /* hexadecimal letter */
-#undef _B
-#define _B (1<<7) /* blank */
-
-static const unsigned char ascii[128] = {
-  _C,   _C,     _C,     _C,     _C,     _C,     _C,     _C,
-  _C,   _C|_S,  _C|_S,  _C|_S,  _C|_S,  _C|_S,  _C,     _C,
-  _C,   _C,     _C,     _C,     _C,     _C,     _C,     _C,
-  _C,   _C,     _C,     _C,     _C,     _C,     _C,     _C,
-  _S|_B, _P,    _P,     _P,     _P,     _P,     _P,     _P,
-  _P,   _P,     _P,     _P,     _P,     _P,     _P,     _P,
-  _N,   _N,     _N,     _N,     _N,     _N,     _N,     _N,
-  _N,   _N,     _P,     _P,     _P,     _P,     _P,     _P,
-  _P,   _U|_X,  _U|_X,  _U|_X,  _U|_X,  _U|_X,  _U|_X,  _U,
-  _U,   _U,     _U,     _U,     _U,     _U,     _U,     _U,
-  _U,   _U,     _U,     _U,     _U,     _U,     _U,     _U,
-  _U,   _U,     _U,     _P,     _P,     _P,     _P,     _P,
-  _P,   _L|_X,  _L|_X,  _L|_X,  _L|_X,  _L|_X,  _L|_X,  _L,
-  _L,   _L,     _L,     _L,     _L,     _L,     _L,     _L,
-  _L,   _L,     _L,     _L,     _L,     _L,     _L,     _L,
-  _L,   _L,     _L,     _P,     _P,     _P,     _P,     _C
-};
-
-int Curl_isspace(int c)
-{
-  if((c < 0) || (c >= 0x80))
-    return FALSE;
-  return (ascii[c] & _S);
-}
-
-int Curl_isdigit(int c)
-{
-  if((c < 0) || (c >= 0x80))
-    return FALSE;
-  return (ascii[c] & _N);
-}
-
-int Curl_isalnum(int c)
-{
-  if((c < 0) || (c >= 0x80))
-    return FALSE;
-  return (ascii[c] & (_N|_U|_L));
-}
-
-int Curl_isxdigit(int c)
-{
-  if((c < 0) || (c >= 0x80))
-    return FALSE;
-  return (ascii[c] & (_N|_X));
-}
-
-int Curl_isgraph(int c)
-{
-  if((c < 0) || (c >= 0x80) || (c == ' '))
-    return FALSE;
-  return (ascii[c] & (_N|_X|_U|_L|_P|_S));
-}
-
-int Curl_isprint(int c)
-{
-  if((c < 0) || (c >= 0x80))
-    return FALSE;
-  return (ascii[c] & (_N|_X|_U|_L|_P|_S));
-}
-
-int Curl_isalpha(int c)
-{
-  if((c < 0) || (c >= 0x80))
-    return FALSE;
-  return (ascii[c] & (_U|_L));
-}
-
-int Curl_isupper(int c)
-{
-  if((c < 0) || (c >= 0x80))
-    return FALSE;
-  return (ascii[c] & (_U));
-}
-
-int Curl_islower(int c)
-{
-  if((c < 0) || (c >= 0x80))
-    return FALSE;
-  return (ascii[c] & (_L));
-}
-
-int Curl_iscntrl(int c)
-{
-  if((c < 0) || (c >= 0x80))
-    return FALSE;
-  return (ascii[c] & (_C));
-}
-
index c70945a8d2009b89b745b40bd36035e7efcb8f0c..20b1e21ebb60a378b7032c2146faf67ba02ba500 100644 (file)
  *
  ***************************************************************************/
 
-#include "curl_setup.h"
+#define ISLOWHEXALHA(x) (((x) >= 'a') && ((x) <= 'f'))
+#define ISUPHEXALHA(x) (((x) >= 'A') && ((x) <= 'F'))
 
-int Curl_isspace(int c);
-int Curl_isdigit(int c);
-int Curl_isalnum(int c);
-int Curl_isxdigit(int c);
-int Curl_isgraph(int c);
-int Curl_isprint(int c);
-int Curl_isalpha(int c);
-int Curl_isupper(int c);
-int Curl_islower(int c);
-int Curl_iscntrl(int c);
+#define ISLOWCNTRL(x) ((x) >= 0 && ((x) <= 0x1f))
+#define IS7F(x) ((x) == 0x7f)
 
-#define ISSPACE(x)  (Curl_isspace((int)  ((unsigned char)x)))
-#define ISDIGIT(x)  (Curl_isdigit((int)  ((unsigned char)x)))
-#define ISALNUM(x)  (Curl_isalnum((int)  ((unsigned char)x)))
-#define ISXDIGIT(x) (Curl_isxdigit((int) ((unsigned char)x)))
-#define ISGRAPH(x)  (Curl_isgraph((int)  ((unsigned char)x)))
-#define ISALPHA(x)  (Curl_isalpha((int)  ((unsigned char)x)))
-#define ISPRINT(x)  (Curl_isprint((int)  ((unsigned char)x)))
-#define ISUPPER(x)  (Curl_isupper((int)  ((unsigned char)x)))
-#define ISLOWER(x)  (Curl_islower((int)  ((unsigned char)x)))
-#define ISCNTRL(x)  (Curl_iscntrl((int)  ((unsigned char)x)))
-#define ISASCII(x)  (((x) >= 0) && ((x) <= 0x80))
+#define ISLOWPRINT(x) (((x) >= 9) && ((x) <= 0x0d))
 
-#define ISBLANK(x)  (int)((((unsigned char)x) == ' ') ||        \
-                          (((unsigned char)x) == '\t'))
+#define ISPRINT(x)  (ISLOWPRINT(x) || (((x) >= ' ') && ((x) <= 0x7e)))
+#define ISGRAPH(x)  (ISLOWPRINT(x) || (((x) > ' ') && ((x) <= 0x7e)))
+#define ISCNTRL(x) (ISLOWCNTRL(x) || IS7F(x))
+#define ISALPHA(x) (ISLOWER(x) || ISUPPER(x))
+#define ISXDIGIT(x) (ISDIGIT(x) || ISLOWHEXALHA(x) || ISUPHEXALHA(x))
+#define ISALNUM(x)  (ISDIGIT(x) || ISLOWER(x) || ISUPPER(x))
+#define ISUPPER(x)  (((x) >= 'A') && ((x) <= 'Z'))
+#define ISLOWER(x)  (((x) >= 'a') && ((x) <= 'z'))
+#define ISDIGIT(x)  (((x) >= '0') && ((x) <= '9'))
+#define ISBLANK(x)  (((x) == ' ') || ((x) == '\t'))
+#define ISSPACE(x)  (ISBLANK(x) || (((x) >= 0xa) && ((x) <=0x0d)))
 
 #endif /* HEADER_CURL_CTYPE_H */
index 290dbe8faa10610a609f8084ee3c3499c48e64e8..0b836851ac7d5157e314b771fee48bd6e23ed2c6 100644 (file)
@@ -125,7 +125,7 @@ CHUNKcode Curl_httpchunk_read(struct Curl_easy *data,
   while(length) {
     switch(ch->state) {
     case CHUNK_HEX:
-      if(isxdigit_ascii(*datap)) {
+      if(ISXDIGIT(*datap)) {
         if(ch->hexindex < CHUNK_MAXNUM_LEN) {
           ch->hexbuffer[ch->hexindex] = *datap;
           datap++;
index b48ca94e1ac20262d64843a6e6bcaae0160d5ffd..ef4db8c257c4fad92b364346a02547b29da58d37 100644 (file)
@@ -214,7 +214,6 @@ rem
       call :element %1 lib "timediff.c" %3
       call :element %1 lib "nonblock.c" %3
       call :element %1 lib "warnless.c" %3
-      call :element %1 lib "curl_ctype.c" %3
       call :element %1 lib "curl_multibyte.c" %3
       call :element %1 lib "version_win32.c" %3
       call :element %1 lib "dynbuf.c" %3
index 92c12078af1fc1a403673cebc7ba1d7d9ef009b3..bdf663f9504fdab17abcbaaabab4a48237fcb4d2 100644 (file)
@@ -36,7 +36,6 @@ CURLX_CFILES = \
   ../lib/timediff.c \
   ../lib/nonblock.c \
   ../lib/warnless.c \
-  ../lib/curl_ctype.c \
   ../lib/curl_multibyte.c \
   ../lib/version_win32.c \
   ../lib/dynbuf.c
index 927d3c1492854e836bca1b3f7a15e7341225226e..00c1b893c7a7fa8ccf8390f01a6af422148f255e 100644 (file)
@@ -499,7 +499,7 @@ static int get_param_part(struct OperationConfig *config, char endchar,
   sep = *p;
   *endpos = '\0';
   while(sep == ';') {
-    while(ISSPACE(*++p))
+    while(p++ && ISSPACE(*p))
       ;
 
     if(!endct && checkprefix("type=", p)) {
index 83a8af45ba579019883b0fe0353c114a217f869c..ed7001134c065dbedee0f0f346bf9ba8ab3e322d 100644 (file)
@@ -68,7 +68,7 @@ noinst_PROGRAMS = chkhostname libauthretry libntlmconnect                \
  lib3010 lib3025 lib3026
 
 chkdecimalpoint_SOURCES = chkdecimalpoint.c ../../lib/mprintf.c \
- ../../lib/curl_ctype.c  ../../lib/dynbuf.c ../../lib/strdup.c
+ ../../lib/dynbuf.c ../../lib/strdup.c
 chkdecimalpoint_LDADD =
 chkdecimalpoint_CPPFLAGS = $(AM_CPPFLAGS) -DCURL_STATICLIB \
  -DCURLX_NO_MEMORY_CALLBACKS -DBUILDING_LIBCURL
index 2953704e342b615a054d73f4d5ee48d3a4bd72fd..ccc65d2b80d2ad76e297e2a93c27fb756d60513c 100644 (file)
@@ -31,7 +31,6 @@ CURLX_SRCS = \
  ../../lib/strtoofft.c \
  ../../lib/warnless.c \
  ../../lib/timediff.c \
- ../../lib/curl_ctype.c \
  ../../lib/dynbuf.c \
  ../../lib/strdup.c \
  ../../lib/curl_multibyte.c
index 1bdbf79a41976a2d8931e978cf04f84578dfe2e4..46b47b395be576ddfdfe9c4e78a38442d8e0dde7 100644 (file)
@@ -662,7 +662,6 @@ CURL_FROM_LIBCURL=$(CURL_DIROBJ)\tool_hugehelp.obj \
  $(CURL_DIROBJ)\nonblock.obj \\r
  $(CURL_DIROBJ)\strtoofft.obj \\r
  $(CURL_DIROBJ)\warnless.obj \\r
- $(CURL_DIROBJ)\curl_ctype.obj \\r
  $(CURL_DIROBJ)\curl_multibyte.obj \\r
  $(CURL_DIROBJ)\version_win32.obj \\r
  $(CURL_DIROBJ)\dynbuf.obj\r
@@ -682,8 +681,6 @@ $(CURL_DIROBJ)\strtoofft.obj: ../lib/strtoofft.c
        $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/strtoofft.c\r
 $(CURL_DIROBJ)\warnless.obj: ../lib/warnless.c\r
        $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/warnless.c\r
-$(CURL_DIROBJ)\curl_ctype.obj: ../lib/curl_ctype.c\r
-       $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/curl_ctype.c\r
 $(CURL_DIROBJ)\curl_multibyte.obj: ../lib/curl_multibyte.c\r
        $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/curl_multibyte.c\r
 $(CURL_DIROBJ)\version_win32.obj: ../lib/version_win32.c\r