Re: A micro-optimisation for walkdir()

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2020-09-02T14:34:58Z
Lists: pgsql-hackers
Thomas Munro <thomas.munro@gmail.com> writes:
> You don't need to call stat() just to find out if a dirent is a file
> or directory, most of the time.  Please see attached.

Hm.  If we do this, I can see wanting to apply the knowledge in more
places than walkdir().  Is it possible to extract out the nonstandard
bits into a reusable subroutine?  I'm envisioning an API more or less
like

   extern enum PGFileType identify_file_type(const char *path,
                                             const struct dirent *de,
                                             bool look_thru_symlinks);

			regards, tom lane



Commits

  1. Add d_type to our Windows dirent emulation.

  2. Skip unnecessary stat() calls in walkdir().