Skip to content

Commit 61ee92d

Browse files
ted-xiecopybara-github
authored andcommitted
Pre-compile ZipFilterAction regex
String.match() compiles the regex on every single invocation. This is not desirable in the inner loop. We can save on regex re-compilation by pre-compiling outside of the nested loop. PiperOrigin-RevId: 746029685 Change-Id: I8d4001a83804dc6f4493598fd61fe60e011ff08b
1 parent 8fdc00f commit 61ee92d

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/tools/java/com/google/devtools/build/android/ZipFilterAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,13 @@ static Multimap<String, Long> getEntriesToOmit(
197197
}
198198
// Match any string that ends with any of the filter file types
199199
String filterRegex = String.format(".*(%s)$", Joiner.on("|").join(escapedFilterTypes));
200+
Pattern filterPattern = Pattern.compile(filterRegex);
200201

201202
ImmutableSetMultimap.Builder<String, Long> entriesToOmit = ImmutableSetMultimap.builder();
202203
for (Path filterZip : filterZips) {
203204
try (ZipReader zip = new ZipReader(filterZip.toFile())) {
204205
for (ZipFileEntry entry : zip.entries()) {
205-
if (filterTypes.isEmpty() || entry.getName().matches(filterRegex)) {
206+
if (filterTypes.isEmpty() || filterPattern.matcher(entry.getName()).matches()) {
206207
entriesToOmit.put(entry.getName(), entry.getCrc());
207208
}
208209
}

0 commit comments

Comments
 (0)