Re: [PATCH] wip: change ISSPACE to use ascii whitespace check.

Steffen Nurpmeso <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <20260220140748.lgePa5Jh@steffen%sdaoden.eu>
P.S.:

Steffen Nurpmeso wrote in
 <20260220005636.rXyivqZV@steffen%sdaoden.eu>:
 |Alejandro Colomar wrote in
 | <aZeOM3sbAm6t-mq6@devuan>:
 ||On 2026-02-19T23:18:16+0100, Steffen Nurpmeso wrote:
 ||> Alejandro Colomar wrote in
 ||>  <aZeGabzZUpS4fT4B@devuan>:
 ||>|On 2026-02-19T22:15:29+0100, Steffen Nurpmeso wrote:
 ||>|> Crystal Kolipe via Mutt-dev wrote in
 ||>|>  <[email protected]>:
 ||>|>|On Thu, Feb 19, 2026 at 02:32:45PM +0100, Alejandro Colomar via \
 ||>|>|Mutt-dev \
 ||>|>|\
 ||>|>|wrote:
 ||>|> 
 ||>|> I think "the best" is a table lookup.
 | ...
 ||Of course, a LUT beats anything, but the implementation is far from
 ||readable.  And it only works for isascii(3) functions, but not so much
 ||for skipws(), because you need to write a loop, at which point you don't

Btw, where is my head, i remembered i do also have a lookup table
for RFC 5322 syntax.
Maybe because i have a logical error in how the actual code works
(it "requotes" local parts which contain quotes (or should), ie it
actively changes local-parts), but that does not affect the lookup
table.  So with it i can

  /*! (RFC 5234, B.1. Core Rules; \r{su_imf_c_SP()} or \r{su_imf_c_HT()}.) */
  SINLINE boole su_imf_c_WSP(char c) {return (a_X(c, su_IMF_C_SP | su_IMF_C_HT));}
  /*! Any of \r{su_imf_c_SP()}, \r{su_imf_c_HT()}, \r{su_imf_c_LF()} or \r{su_imf_c_CR()}. */
  SINLINE boole su_imf_c_ANY_WSP(char c) {return (a_X(c, su_IMF_C_SP | su_IMF_C_HT | su_IMF_C_LF | su_IMF_C_CR));}

(where a_X is

  #undef a_X
  #if su__IMF_TABLE_SIZE == U8_MAX
  # define a_X(X,Y) ((su__imf_c_tbl[S(u8,X)] & (Y)) != 0)
  #elif su__IMF_TABLE_SIZE == S8_MAX
  # define a_X(X,Y) (S(u8,X) <= S8_MAX && (su__imf_c_tbl[S(u8,X)] & (Y)) != 0)
  #else
  # error su__IMF_TABLE_SIZE must be U8_MAX or S8_MAX
  #endif
 
), which is quite comfortable.
That is, in short, and to end this, i think in working internet
message format function call overhead does practically not matter,
but still i prefer table lookups :)

Ciao already here, dear Alejandro.


/* imf_table_dump {{{ */
#ifdef a_IMF_TABLE_DUMP
SINLINE boole a_imf_c_ALPHA(char c) {return ((c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A));}
SINLINE boole a_imf_c_DIGIT(char c) {return (c >= 0x30 && c <= 0x39);}
SINLINE boole a_imf_c_VCHAR(char c) {return (c >= 0x21 && c <= 0x7E);}
SINLINE boole a_imf_c_atext(char c){
	return (a_imf_c_ALPHA(c) || a_imf_c_DIGIT(c) ||
			c == '!' || c == '#' || c == '$' || c == '%' || c == '&' || c == '\'' || c == '*' ||
			c == '+' || c == '-' || c == '/' || c == '=' || c == '?' || c == '^' || c == '_' || c == '`' ||
			c == '{' || c == '|' || c == '}' || c == '~');
}
SINLINE boole a_imf_c_ctext(char c) {return ((c >= 33 && c <= 39) || (c >= 42 && c <= 91) || (c >= 93 && c <= 126));}
SINLINE boole a_imf_c_dtext(char c) {return ((c >= 33 && c <= 90) || (c >= 94 && c <= 126));}
SINLINE boole a_imf_c_qtext(char c) {return (c == 33 || (c >= 35 && c <= 91) || (c >= 93 && c <= 126));}
SINLINE boole a_imf_c_special(char c){
	return (c == '(' || c == ')' || c == '<' || c == '>' || c == '[' || c == ']' || c == ':' || c == ';' ||
			c == '@' || c == '\\' || c == ',' || c == '.' || su_imf_c_DQUOTE(c));
}
SINLINE boole a_imf_c_obs_NO_WS_CTL(char c){
	return (c >= 1 && c <= 8) || (c == 11 || c == 12) || (c >= 14 && c <= 31) || (c == 127);
}

SINLINE boole a_imf_c_CR(char c) {return (c == 0x0D);}
SINLINE boole a_imf_c_DQUOTE(char c) {return (c == 0x22);}
SINLINE boole a_imf_c_HT(char c) {return (c == 0x09);}
SINLINE boole a_imf_c_LF(char c) {return (c == 0x0A);}
SINLINE boole a_imf_c_SP(char c) {return (c == 0x20);}

void
su_imf_table_dump(void){
	char c;

	fputs("#undef a_X\n", stdout);
	fputs("#define a_X(X) CONCAT(su_IMF_C_, X)\n", stdout);
	fputs("u16 const su__imf_c_tbl[su__IMF_TABLE_SIZE + 1] = { /* {{{ */\n", stdout);

	for(c = '\0';;){
		fputc('\t', stdout);
		if(a_imf_c_ALPHA(c))
			fputs("a_X(ALPHA) | ", stdout);
		if(a_imf_c_DIGIT(c))
			fputs("a_X(DIGIT) | ", stdout);
		if(a_imf_c_VCHAR(c))
			fputs("a_X(VCHAR) | ", stdout);
		if(a_imf_c_atext(c))
			fputs("a_X(ATEXT) | ", stdout);
		if(a_imf_c_ctext(c))
			fputs("a_X(CTEXT) | ", stdout);
		if(a_imf_c_dtext(c))
			fputs("a_X(DTEXT) | ", stdout);
		if(a_imf_c_qtext(c))
			fputs("a_X(QTEXT) | ", stdout);
		if(a_imf_c_special(c))
			fputs("a_X(SPECIAL) | ", stdout);
		if(a_imf_c_obs_NO_WS_CTL(c))
			fputs("a_X(NO_WS_CTL) | ", stdout);

		if(a_imf_c_CR(c))
			fputs("a_X(CR) | ", stdout);
		if(a_imf_c_DQUOTE(c))
			fputs("a_X(DQUOTE) | ", stdout);
		if(a_imf_c_HT(c))
			fputs("a_X(HT) | ", stdout);
		if(a_imf_c_LF(c))
			fputs("a_X(LF) | ", stdout);
		if(a_imf_c_SP(c))
			fputs("a_X(SP) | ", stdout);

		fputs("0,\n", stdout);

		if(c++ == S8_MAX)
			break;
	}

	fputs("}; /* }}} */\n", stdout);
}
#endif /* }}} a_IMF_TABLE_DUMP */

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.