mirror of https://github.com/webpack/webpack.git
performance improvements for FunctionModuleTemplate
This commit is contained in:
parent
31f2e6d1f7
commit
e7922011d6
|
|
@ -11,6 +11,22 @@ const Template = require("./Template");
|
|||
|
||||
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
||||
|
||||
const joinIterableWithComma = iterable => {
|
||||
// This is more performant than Array.from().join(", ")
|
||||
// as it doesn't create an array
|
||||
let str = "";
|
||||
let first = true;
|
||||
for (const item of iterable) {
|
||||
str += item;
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
str += ", ";
|
||||
}
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
class FunctionModuleTemplatePlugin {
|
||||
constructor({ compilation }) {
|
||||
this.compilation = compilation;
|
||||
|
|
@ -62,9 +78,11 @@ class FunctionModuleTemplatePlugin {
|
|||
const req = module.readableIdentifier(
|
||||
moduleTemplate.runtimeTemplate.requestShortener
|
||||
);
|
||||
source.add("/*!****" + req.replace(/./g, "*") + "****!*\\\n");
|
||||
source.add(" !*** " + req.replace(/\*\//g, "*_/") + " ***!\n");
|
||||
source.add(" \\****" + req.replace(/./g, "*") + "****/\n");
|
||||
const reqStr = req.replace(/\*\//g, "*_/");
|
||||
const reqStrStar = "*".repeat(reqStr.length);
|
||||
source.add("/*!****" + reqStrStar + "****!*\\\n");
|
||||
source.add(" !*** " + reqStr + " ***!\n");
|
||||
source.add(" \\****" + reqStrStar + "****/\n");
|
||||
const providedExports = moduleGraph.getProvidedExports(module);
|
||||
if (Array.isArray(providedExports)) {
|
||||
if (providedExports.length === 0) {
|
||||
|
|
@ -81,9 +99,9 @@ class FunctionModuleTemplatePlugin {
|
|||
}
|
||||
source.add(
|
||||
Template.toComment(
|
||||
`runtime requirements: ${Array.from(
|
||||
`runtime requirements: ${joinIterableWithComma(
|
||||
chunkGraph.getModuleRuntimeRequirements(module)
|
||||
).join(", ")}`
|
||||
)}`
|
||||
) + "\n"
|
||||
);
|
||||
const usedExports = moduleGraph.getUsedExports(module);
|
||||
|
|
@ -97,7 +115,7 @@ class FunctionModuleTemplatePlugin {
|
|||
} else {
|
||||
source.add(
|
||||
Template.toComment(
|
||||
"exports used: " + Array.from(usedExports).join(", ")
|
||||
"exports used: " + joinIterableWithComma(usedExports)
|
||||
) + "\n"
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue