aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java
diff options
context:
space:
mode:
authorGravatar nharmata <nharmata@google.com>2018-02-27 09:19:54 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2018-02-27 09:22:08 -0800
commit94cf29c120539967b105acc75bdce070e43aa778 (patch)
tree1617ef76049a5786c3d4393ec39842d0a15cd1d1 /src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java
parent7f16496cc027110d37247854115ab68e4c83baa2 (diff)
Optimize Path (and the underlying String) allocations in UnixGlob for the case where a pattern like '*.blah' doesn't match all the dirents.
Before the recent Path.java rewrite, the unconditional allocation here was free/amortized (in the sense that if Blaze ever had to consider the path in question, then we'd be doing the Path allocation anyway and caching the object). But now it's potentially GC churny, especially in the case where a single BUILD file has multiple glob expressions. RELNOTES: None PiperOrigin-RevId: 187185573
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java b/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java
index 9d9cf87ded..74f1fa89a2 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/UnixGlob.java
@@ -819,15 +819,21 @@ public final class UnixGlob {
}
boolean childIsDir = (type == Dirent.Type.DIRECTORY);
String text = dent.getName();
- Path child = base.getChild(text);
+ // Optimize allocations for the case where the pattern doesn't match the dirent.
+ Path child = null;
if (isRecursivePattern) {
// Recurse without shifting the pattern.
if (childIsDir) {
+ child = base.getChild(text);
context.queueGlob(child, childIsDir, idx);
}
}
if (matches(pattern, text, cache)) {
+ if (child == null) {
+ child = base.getChild(text);
+ }
+
// Recurse and consume one segment of the pattern.
if (childIsDir) {
context.queueGlob(child, childIsDir, idx + 1);