diff options
author | Googler <noreply@google.com> | 2017-03-14 10:28:49 +0000 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2017-03-16 09:30:06 -0700 |
commit | b34b6e479a57a9f35789257d64ecac6d242902c1 (patch) | |
tree | 92c33df18a2d4a2e0f9971639797c05548195fa8 | |
parent | 52f7c03d041742e9a5aa5a00e26a4ef0c7de2848 (diff) | |
download | desugar-b34b6e479a57a9f35789257d64ecac6d242902c1.tar.gz |
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
GitOrigin-RevId: 69eb9f53108b1071cef5335a086697b3daf2e509
Change-Id: I8ef31a82e9d54d9385d6a1db31bf014515c29ce6
-rw-r--r-- | java/com/google/devtools/build/android/desugar/Desugar.java | 3 | ||||
-rw-r--r-- | java/com/google/devtools/build/android/desugar/LambdaClassMaker.java | 12 |
2 files changed, 7 insertions, 8 deletions
diff --git a/java/com/google/devtools/build/android/desugar/Desugar.java b/java/com/google/devtools/build/android/desugar/Desugar.java index 877d230..3ef5489 100644 --- a/java/com/google/devtools/build/android/desugar/Desugar.java +++ b/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/java/com/google/devtools/build/android/desugar/LambdaClassMaker.java b/java/com/google/devtools/build/android/desugar/LambdaClassMaker.java index d8f2e28..2a9f9be 100644 --- a/java/com/google/devtools/build/android/desugar/LambdaClassMaker.java +++ b/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()); } } } |