diff options
author | Googler <noreply@google.com> | 2017-03-14 10:28:49 +0000 |
---|---|---|
committer | Yun Peng <pcloudy@google.com> | 2017-03-14 19:45:21 +0000 |
commit | 69eb9f53108b1071cef5335a086697b3daf2e509 (patch) | |
tree | 39a566f03def61d54407700394a01543094b1d3a /src/tools/android/java | |
parent | 9416a460b2db365f81c939c1512bb1f887d3cfa5 (diff) |
Speed-up the search for desugared classes in case of many lambdas by limiting the search to the directory where we expect the file.
--
PiperOrigin-RevId: 150049563
MOS_MIGRATED_REVID=150049563
Diffstat (limited to 'src/tools/android/java')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/desugar/Desugar.java | 3 | ||||
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/desugar/LambdaClassMaker.java | 12 |
2 files changed, 7 insertions, 8 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar.java b/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar.java index 877d2305e3..3ef5489a9e 100644 --- a/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar.java +++ b/src/tools/android/java/com/google/devtools/build/android/desugar/Desugar.java @@ -235,8 +235,7 @@ class Desugar { // Write out the lambda classes we generated along the way for (Map.Entry<Path, LambdaInfo> lambdaClass : lambdas.drain().entrySet()) { - try (InputStream bytecode = - Files.newInputStream(dumpDirectory.resolve(lambdaClass.getKey()))) { + try (InputStream bytecode = Files.newInputStream(lambdaClass.getKey())) { ClassReader reader = rewriter.reader(bytecode); CoreLibraryRewriter.UnprefixingClassWriter writer = rewriter.writer(ClassWriter.COMPUTE_MAXS /*for invoking bridges*/); diff --git a/src/tools/android/java/com/google/devtools/build/android/desugar/LambdaClassMaker.java b/src/tools/android/java/com/google/devtools/build/android/desugar/LambdaClassMaker.java index d8f2e281fb..2a9f9beb80 100644 --- a/src/tools/android/java/com/google/devtools/build/android/desugar/LambdaClassMaker.java +++ b/src/tools/android/java/com/google/devtools/build/android/desugar/LambdaClassMaker.java @@ -54,7 +54,7 @@ class LambdaClassMaker { } /** - * Returns relative paths to .class files generated since the last call to this method together + * Returns absolute paths to .class files generated since the last call to this method together * with a string descriptor of the factory method. */ public Map<Path, LambdaInfo> drain() { @@ -68,12 +68,12 @@ class LambdaClassMaker { // will not contain '/' and searches will fail. So, construct an absolute path from the given // string and use its string representation to find the file we need regardless of host // system's file system - final String rootPathPrefixStr = rootDirectory.resolve(pathPrefix).toString(); + Path rootPathPrefix = rootDirectory.resolve(pathPrefix); + final String rootPathPrefixStr = rootPathPrefix.toString(); - // TODO(kmb): Investigate making this faster in the case of many lambdas // TODO(bazel-team): This could be much nicer with lambdas - try (Stream<Path> results = - Files.walk(rootDirectory) + try (Stream<Path> paths = + Files.list(rootPathPrefix.getParent()) .filter( new Predicate<Path>() { @Override @@ -82,7 +82,7 @@ class LambdaClassMaker { && !generatedClasses.containsKey(path); } })) { - return Iterators.getOnlyElement(results.iterator()); + return Iterators.getOnlyElement(paths.iterator()); } } } |