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
This commit is contained in:
Daniel Stenberg 2022-09-05 12:15:21 +02:00
parent 6f9fb7ec2d
commit f65f750742
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
10 changed files with 19 additions and 166 deletions

View 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 \

View File

@ -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));
}

View File

@ -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 */

View 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++;

View 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

View 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

View 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)) {

View 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

View 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

View File

@ -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