8000 store url as Buffer to avoid serialization warnings · webpack/webpack@17f317b · GitHub
[go: up one dir, main page]

Skip to content

Commit 17f317b

Browse files
committed
store url as Buffer to avoid serialization warnings
makes deserialization cheaper
1 parent e2d214a commit 17f317b

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

lib/RuntimeTemplate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ class RuntimeTemplate {
10311031
const codeGen = codeGenerationResults.get(module, runtime);
10321032
const { data } = codeGen;
10331033
const url = data.get("url");
1034-
if (url) return url;
1034+
if (url) return url.toString();
10351035
const filename = data.get("filename");
10361036
return publicPath + filename;
10371037
}

lib/asset/AssetGenerator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class AssetGenerator extends Generator {
215215
},${encodedContent}`;
216216
}
217217
const data = getData();
218-
data.set("url", encodedSource);
218+
data.set("url", Buffer.from(encodedSource));
219219
return new RawSource(
220220
`${RuntimeGlobals.module}.exports = ${JSON.stringify(
221221
encodedSource

lib/asset/RawDataUrlModule.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class RawDataUrlModule extends Module {
3333
constructor(url, identifier, readableIdentifier) {
3434
super("asset/raw-data-url", null);
3535
this.url = url;
36+
this.urlBuffer = url ? Buffer.from(url) : undefined;
3637
this.identifierStr = identifier || this.url;
3738
this.readableIdentifierStr = readableIdentifier || this.identifierStr;
3839
}
@@ -56,6 +57,7 @@ class RawDataUrlModule extends Module {
5657
* @returns {number} the estimated size of the module (must be non-zero)
5758
*/
5859
size(type) {
60+
if (this.url === undefined) this.url = this.urlBuffer.toString();
5961
return Math.max(1, this.url.length);
6062
}
6163

@@ -97,13 +99,14 @@ class RawDataUrlModule extends Module {
9799
* @returns {CodeGenerationResult} result
98100
*/
99101
codeGeneration(context) {
102+
if (this.url === undefined) this.url = this.urlBuffer.toString();
100103
const sources = new Map();
101104
sources.set(
102105
"javascript",
103106
new RawSource(`module.exports = ${JSON.stringify(this.url)};`)
104107
);
105108
const data = new Map();
106-
data.set("url", this.url);
109+
data.set("url", this.urlBuffer);
107110
const runtimeRequirements = new Set();
108111
runtimeRequirements.add(RuntimeGlobals.module);
109112
return { sources, runtimeRequirements, data };
@@ -115,14 +118,14 @@ class RawDataUrlModule extends Module {
115118
* @returns {void}
116119
*/
117120
updateHash(hash, context) {
118-
hash.update(this.url);
121+
hash.update(this.urlBuffer);
119122
super.updateHash(hash, context);
120123
}
121124

122125
serialize(context) {
123126
const { write } = context;
124127

125-
write(this.url);
128+
write(this.urlBuffer);
126129
write(this.identifierStr);
127130
write(this.readableIdentifierStr);
128131

@@ -132,7 +135,7 @@ class RawDataUrlModule extends Module {
132135
deserialize(context) {
133136
const { read } = context;
134137

135-
this.url = read();
138+
this.urlBuffer = read();
136139
this.identifierStr = read();
137140
this.readableIdentifierStr = read();
138141

0 commit comments

Comments
 (0)
0