diff options
author | Daniel Stenberg <daniel@haxx.se> | 2022-09-05 12:15:21 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2022-09-06 08:36:33 +0200 |
commit | f65f750742068f579f4ee6d8539ed9d5f0afcb85 (patch) | |
tree | 5b10cff13f4d661b5a3f5c6d50c01a905e6e9b3f | |
parent | 6f9fb7ec2d7cb389a0da5a1d0617ce592115a6a8 (diff) | |
download | curl-f65f750742068f579f4ee6d8539ed9d5f0afcb85.tar.gz |
curl_ctype: convert to macros-only
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
-rw-r--r-- | lib/Makefile.inc | 1 | ||||
-rw-r--r-- | lib/curl_ctype.c | 132 | ||||
-rw-r--r-- | lib/curl_ctype.h | 40 | ||||
-rw-r--r-- | lib/http_chunks.c | 2 | ||||
-rw-r--r-- | projects/generate.bat | 1 | ||||
-rw-r--r-- | src/Makefile.inc | 1 | ||||
-rw-r--r-- | src/tool_formparse.c | 2 | ||||
-rw-r--r-- | tests/libtest/Makefile.inc | 2 | ||||
-rw-r--r-- | tests/server/Makefile.inc | 1 | ||||
-rw-r--r-- | winbuild/MakefileBuild.vc | 3 |
10 files changed, 19 insertions, 166 deletions
diff --git a/lib/Makefile.inc b/lib/Makefile.inc index 9bd8e324b..af47fe6a2 100644 --- a/lib/Makefile.inc +++ b/lib/Makefile.inc @@ -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 index e1a844515..000000000 --- a/lib/curl_ctype.c +++ /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)); -} - diff --git a/lib/curl_ctype.h b/lib/curl_ctype.h index c70945a8d..20b1e21eb 100644 --- a/lib/curl_ctype.h +++ b/lib/curl_ctype.h @@ -24,32 +24,24 @@ * ***************************************************************************/ -#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 */ diff --git a/lib/http_chunks.c b/lib/http_chunks.c index 290dbe8fa..0b836851a 100644 --- a/lib/http_chunks.c +++ b/lib/http_chunks.c @@ -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++; diff --git a/projects/generate.bat b/projects/generate.bat index b48ca94e1..ef4db8c25 100644 --- a/projects/generate.bat +++ b/projects/generate.bat @@ -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 diff --git a/src/Makefile.inc b/src/Makefile.inc index 92c12078a..bdf663f95 100644 --- a/src/Makefile.inc +++ b/src/Makefile.inc @@ -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 diff --git a/src/tool_formparse.c b/src/tool_formparse.c index 927d3c149..00c1b893c 100644 --- a/src/tool_formparse.c +++ b/src/tool_formparse.c @@ -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)) { diff --git a/tests/libtest/Makefile.inc b/tests/libtest/Makefile.inc index 83a8af45b..ed7001134 100644 --- a/tests/libtest/Makefile.inc +++ b/tests/libtest/Makefile.inc @@ -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 diff --git a/tests/server/Makefile.inc b/tests/server/Makefile.inc index 2953704e3..ccc65d2b8 100644 --- a/tests/server/Makefile.inc +++ b/tests/server/Makefile.inc @@ -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 diff --git a/winbuild/MakefileBuild.vc b/winbuild/MakefileBuild.vc index 1bdbf79a4..46b47b395 100644 --- a/winbuild/MakefileBuild.vc +++ b/winbuild/MakefileBuild.vc @@ -662,7 +662,6 @@ CURL_FROM_LIBCURL=$(CURL_DIROBJ)\tool_hugehelp.obj \ $(CURL_DIROBJ)\nonblock.obj \
$(CURL_DIROBJ)\strtoofft.obj \
$(CURL_DIROBJ)\warnless.obj \
- $(CURL_DIROBJ)\curl_ctype.obj \
$(CURL_DIROBJ)\curl_multibyte.obj \
$(CURL_DIROBJ)\version_win32.obj \
$(CURL_DIROBJ)\dynbuf.obj
@@ -682,8 +681,6 @@ $(CURL_DIROBJ)\strtoofft.obj: ../lib/strtoofft.c $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/strtoofft.c
$(CURL_DIROBJ)\warnless.obj: ../lib/warnless.c
$(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/warnless.c
-$(CURL_DIROBJ)\curl_ctype.obj: ../lib/curl_ctype.c
- $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/curl_ctype.c
$(CURL_DIROBJ)\curl_multibyte.obj: ../lib/curl_multibyte.c
$(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/curl_multibyte.c
$(CURL_DIROBJ)\version_win32.obj: ../lib/version_win32.c
|