Re: [PATCH] Refactor "if(strspn(str, ...) == strlen(str)" code - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [PATCH] Refactor "if(strspn(str, ...) == strlen(str)" code
Date
Msg-id 4419.1481216234@sss.pgh.pa.us
Whole thread Raw
In response to [PATCH] Refactor "if(strspn(str, ...) == strlen(str)" code  (Aleksander Alekseev <a.alekseev@postgrespro.ru>)
Responses Re: [PATCH] Refactor "if(strspn(str, ...) == strlen(str)" code  (Aleksander Alekseev <a.alekseev@postgrespro.ru>)
Re: [HACKERS] [PATCH] Refactor "if(strspn(str, ...) == strlen(str)"code  (Aleksander Alekseev <a.alekseev@postgrespro.ru>)
List pgsql-hackers
Aleksander Alekseev <a.alekseev@postgrespro.ru> writes:
> How about rewriting such a code like this?
> if (pg_str_containsonly(str, " \t\n\r\f"))

Function name seems weirdly spelled.  Also, I believe that in nearly all
use-cases the number of data characters that would typically be examined
is small, so I have serious doubts that the "optimized" implementation
you propose is actually faster than a naive one; it may be slower, and
it's certainly longer and harder to understand/test.

Whether it's worth worrying about, I dunno.  This is hardly the only
C idiom you need to be familiar with to read the PG code.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Declarative partitioning - another take
Next
From: Jeff Janes
Date:
Subject: postgres_fdw bug in 9.6