summaryrefslogtreecommitdiffstats
path: root/bftw.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-02-01 07:00:40 -0500
committerTavian Barnes <tavianator@tavianator.com>2018-02-01 11:19:17 -0500
commit15152c2f2e169e824f8a1da400b8c3a0b195f8f4 (patch)
tree4b9230a9a0d74fcf866f28273ea32b292b0e7808 /bftw.c
parent113edac300ca54359d34c748c2b7057ba493ab4e (diff)
downloadbfs-15152c2f2e169e824f8a1da400b8c3a0b195f8f4.tar.xz
bftw: Open-code the "."/".." checks
GCC doesn't (yet) produce very fast code for strcmp() against constant strings (see https://gcc.gnu.org/PR78809), so hand-coding the comparison manually helps significantly.
Diffstat (limited to 'bftw.c')
-rw-r--r--bftw.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/bftw.c b/bftw.c
index 9f80c76..7c65655 100644
--- a/bftw.c
+++ b/bftw.c
@@ -1074,11 +1074,12 @@ int bftw(const char *path, bftw_fn *fn, int nopenfd, enum bftw_flags flags, void
break;
}
- if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) {
+ const char *name = de->d_name;
+ if (name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) {
continue;
}
- if (bftw_path_concat(&state, de->d_name) != 0) {
+ if (bftw_path_concat(&state, name) != 0) {
goto fail;
}
@@ -1109,7 +1110,7 @@ int bftw(const char *path, bftw_fn *fn, int nopenfd, enum bftw_flags flags, void
continue;
}
- if (bftw_push(&state, de->d_name) != 0) {
+ if (bftw_push(&state, name) != 0) {
goto fail;
}
}