Re: [PATCH] Use strchr() to search for a single character
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Dmitry Mityugov <d.mityugov@postgrespro.ru>,
Corey Huinker <corey.huinker@gmail.com>, pgsql-hackers@postgresql.org
Date: 2025-07-22T22:58:51Z
Lists: pgsql-hackers
On Wed, 23 Jul 2025 at 10:36, Tom Lane <tgl@sss.pgh.pa.us> wrote: > > David Rowley <dgrowleyml@gmail.com> writes: > > 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. > > I was wondering if that might be true. However, your godbolt results > show that MSVC doesn't do this optimization, and the usage in > pgmkdirp.c is inside "#ifdef WIN32", so maybe it's worth fixing there. Yeah, I noticed MSVC not doing the rewrite. I didn't notice the mentioned use case was within an #ifdef WIN32. I'm currently thinking we should just fix the pgmkdirp.c instance and call it good. David
Commits
-
Use strchr instead of strstr for single-char lookups
- 039f7ee0fe9a 19 (unreleased) landed