Skip to content

Commit 0d23fbd

Browse files
committed
comments
1 parent 9c19c9c commit 0d23fbd

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/dir.cc

+7-5
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,18 @@ bool ListDir(int dir_fd, Arena& arena, std::vector<char*>& entries, bool precomp
116116
entries.clear();
117117
return false;
118118
}
119-
if (n == 0) break;
120119
for (int pos = 0; pos < n;) {
121120
auto* ent = reinterpret_cast<linux_dirent64*>(buf + pos);
122121
if (!Dots(ent->d_name)) entries.push_back(ent->d_name);
123122
pos += ent->d_reclen;
124-
// It's tempting to bail here if n + sizeof(linux_dirent64) + 512 <= n. After all, there
125-
// was enough space for another entry but SYS_getdents64 didn't write it, so this must be
126-
// the end of the directory listing, right? Unfortuatenly, no. SYS_getdents64 is finicky.
127-
// It sometimes writes a partial list of entries even if the full list would fit.
128123
}
124+
if (n == 0) break;
125+
// The following optimization relies on SYS_getdents64 always returning as many
126+
// entries as would fit. This is not guaranteed by the specification and I don't
127+
// know if this is true in practice. The optimization has no measurable effect on
128+
// gitstatus performance, so it's turned off.
129+
//
130+
// if (n + sizeof(linux_dirent64) + 512 <= kBufSize) break;
129131
}
130132

131133
if (case_sensitive) {

0 commit comments

Comments
 (0)