Skip to content

Commit

Permalink
Reduce garbage created in syscall cache.
Browse files Browse the repository at this point in the history
`Path.getBaseName()` allocates a new string, doing so in a loop is wasteful.

PiperOrigin-RevId: 608576584
Change-Id: Idcbbd5887f1f288a193d3c471d49310395bcf097
  • Loading branch information
meisterT authored and copybara-github committed Feb 20, 2024
1 parent e061a02 commit a80cdb0
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ public DirentTypeWithSkip getType(Path path, Symlinks symlinks) throws IOExcepti
// stat.
Object result = readdirCache.getIfPresent(parent);
if (result != null && !(result instanceof IOException)) {
String baseName = path.getBaseName();
for (Dirent dirent : (Collection<Dirent>) result) { // unchecked cast
// TODO(djasper): Dealing with filesystem case is a bit of a code smell. Figure out a better
// way to store Dirents, e.g. with names normalized.
if (path.getFileSystem().isFilePathCaseSensitive()
&& !dirent.getName().equals(path.getBaseName())) {
if (path.getFileSystem().isFilePathCaseSensitive() && !dirent.getName().equals(baseName)) {
continue;
}
if (!path.getFileSystem().isFilePathCaseSensitive()
&& !dirent.getName().equalsIgnoreCase(path.getBaseName())) {
&& !dirent.getName().equalsIgnoreCase(baseName)) {
continue;
}
if (dirent.getType() == Dirent.Type.SYMLINK && symlinks == Symlinks.FOLLOW) {
Expand Down

0 comments on commit a80cdb0

Please sign in to comment.