Merge pull request #9032 from Connormiha/optimize-check-availible-chunk

Move isAvailible from method to module
This commit is contained in:
Tobias Koppers 2019-05-09 09:45:20 +02:00 committed by GitHub
commit 251605e0cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 19 deletions

View File

@ -109,6 +109,23 @@ const getModulesSizes = modules => {
return sizes;
};
/**
* @param {Chunk} a chunk
* @param {Chunk} b chunk
* @returns {boolean} true, if a is always a parent of b
*/
const isAvailableChunk = (a, b) => {
const queue = new Set(b.groupsIterable);
for (const chunkGroup of queue) {
if (a.isInGroup(chunkGroup)) continue;
if (chunkGroup.isInitial()) return false;
for (const parent of chunkGroup.parentsIterable) {
queue.add(parent);
}
}
return true;
};
class ChunkGraphModule {
constructor() {
/** @type {SortableSet<Chunk>} */
@ -622,31 +639,14 @@ class ChunkGraph {
return false;
}
/**
* @param {Chunk} a chunk
* @param {Chunk} b chunk
* @returns {boolean} true, if a is always a parent of b
*/
const isAvailable = (a, b) => {
const queue = new Set(b.groupsIterable);
for (const chunkGroup of queue) {
if (a.isInGroup(chunkGroup)) continue;
if (chunkGroup.isInitial()) return false;
for (const parent of chunkGroup.parentsIterable) {
queue.add(parent);
}
}
return true;
};
const hasRuntimeA = chunkA.hasRuntime();
const hasRuntimeB = chunkB.hasRuntime();
if (hasRuntimeA !== hasRuntimeB) {
if (hasRuntimeA) {
return isAvailable(chunkA, chunkB);
return isAvailableChunk(chunkA, chunkB);
} else if (hasRuntimeB) {
return isAvailable(chunkB, chunkA);
return isAvailableChunk(chunkB, chunkA);
} else {
return false;
}