Re: [PATCH] Use strchr() to search for a single character - Mailing list pgsql-hackers

From David Rowley
Subject Re: [PATCH] Use strchr() to search for a single character
Date
Msg-id CAApHDvo-9k5qrsQhO7UdX+ciSTPe6wbG2MXxcCCfZ_DdmtnbDQ@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] Use strchr() to search for a single character  (Dmitry Mityugov <d.mityugov@postgrespro.ru>)
Responses Re: [PATCH] Use strchr() to search for a single character
List pgsql-hackers
On Wed, 23 Jul 2025 at 09:34, Dmitry Mityugov <d.mityugov@postgrespro.ru> wrote:
> Thank you for your attention to this problem. The code in
> contrib/fuzzystrmatch/dmetaphone.c indeed uses several calls to strstr()
> to search for a single character, but it also uses strstr() to search
> for strings that consist of more than a single character on adjacent
> lines, and replacing half of those strstr()s with strchr()s would make
> the code less consistent in my opinion.

That depends on what you're making consistent. If the consistency is
that we always use strchr() when the search is for a single char, then
it's not consistent to ignore that one.

Looking at [1], it seems even ancient versions of gcc and clang
rewrite the strstr() into a strchr() call when the search term is a
single char string. So it might not be worth doing to any trouble
here.

[1] https://godbolt.org/z/q1xcKdzd7

David



pgsql-hackers by date:

Previous
From: Dave Cramer
Date:
Subject: More protocol.h replacements this time into walsender.c
Next
From: "Joel Jacobson"
Date:
Subject: Re: [PATCH] Optimize ProcSignal to avoid redundant SIGUSR1 signals