Switch to writeMultiDexDirectoryCommon

This commit is contained in:
Lanchon 2017-09-24 01:02:32 -03:00
parent ba40d19575
commit 44fc0cf19e

View File

@ -73,7 +73,7 @@ public class DexIO {
} }
Object lock = new Object(); Object lock = new Object();
synchronized (lock) { // avoid multiple synchronizations in single-threaded mode synchronized (lock) { // avoid multiple synchronizations in single-threaded mode
writeCommon(directory, nameIterator, null, null, Iterators.peekingIterator(classes.iterator()), writeMultiDexDirectoryCommon(directory, nameIterator, Iterators.peekingIterator(classes.iterator()),
minMainDexClassCount, minimalMainDex, dexFile.getOpcodes(), maxDexPoolSize, logger, lock); minMainDexClassCount, minimalMainDex, dexFile.getOpcodes(), maxDexPoolSize, logger, lock);
} }
} }
@ -95,8 +95,8 @@ public class DexIO {
callables.add(new Callable<Void>() { callables.add(new Callable<Void>() {
@Override @Override
public Void call() throws IOException { public Void call() throws IOException {
writeCommon(directory, nameIterator, null, null, batchedIterator, 0, false, dexFile.getOpcodes(), writeMultiDexDirectoryCommon(directory, nameIterator, batchedIterator, 0, false,
maxDexPoolSize, logger, lock); dexFile.getOpcodes(), maxDexPoolSize, logger, lock);
return null; return null;
} }
}); });
@ -126,7 +126,7 @@ public class DexIO {
// Common Code // Common Code
private static void writeCommon(File base, DexFileNameIterator nameIterator, String currentName, File currentFile, private static void writeMultiDexDirectoryCommon(File directory, DexFileNameIterator nameIterator,
PeekingIterator<? extends ClassDef> classIterator, int minMainDexClassCount, boolean minimalMainDex, PeekingIterator<? extends ClassDef> classIterator, int minMainDexClassCount, boolean minimalMainDex,
Opcodes opcodes, int maxDexPoolSize, DexIO.Logger logger, Object lock) throws IOException { Opcodes opcodes, int maxDexPoolSize, DexIO.Logger logger, Object lock) throws IOException {
do { do {
@ -145,16 +145,14 @@ public class DexIO {
classIterator.next(); classIterator.next();
fileClassCount++; fileClassCount++;
} }
File file;
synchronized (lock) { synchronized (lock) {
if (currentFile == null) { String name = nameIterator.next();
currentName = nameIterator.next(); file = new File(directory, name);
currentFile = new File(base, currentName); if (logger != null) logger.log(directory, name, fileClassCount);
}
if (logger != null) logger.log(base, currentName, fileClassCount);
if (classIterator instanceof BatchedIterator) ((BatchedIterator) classIterator).preloadBatch(); if (classIterator instanceof BatchedIterator) ((BatchedIterator) classIterator).preloadBatch();
} }
dexPool.writeTo(new FileDataStore(currentFile)); dexPool.writeTo(new FileDataStore(file));
currentFile = null;
minMainDexClassCount = 0; minMainDexClassCount = 0;
minimalMainDex = false; minimalMainDex = false;
} while (classIterator.hasNext()); } while (classIterator.hasNext());