Re: [PATCH] Refactor "if(strspn(str, ...) == strlen(str)" code

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)ru>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Refactor "if(strspn(str, ...) == strlen(str)" code
Date: 2016-12-08 16:57:14
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Aleksander Alekseev <a(dot)alekseev(at)postgrespro(dot)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

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Janes 2016-12-08 17:07:19 postgres_fdw bug in 9.6
Previous Message Robert Haas 2016-12-08 16:54:24 Re: Declarative partitioning - another take