Skip to content

Commit a72636e

Browse files
author
Robert Jackson
authored
Avoid repeated encoding in getTemplateCompiler
`crypto.createHash('md5').update(...)` takes a buffer. The prior code would read the file as a string _then_ convert back to a buffer. Now we only convert to a string for `new vm.Script()` which _requires_ a string. tldr; we convert back and forth from a buffer to a string one less time with the code change here.
1 parent 6b69fef commit a72636e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ function getTemplateCompiler(templateCompilerPath, EmberENV = {}) {
140140
let cacheData = TemplateCompilerCache.get(templateCompilerFullPath);
141141

142142
if (cacheData === undefined) {
143-
let templateCompilerContents = fs.readFileSync(templateCompilerFullPath, { encoding: 'utf-8' });
143+
let templateCompilerContents = fs.readFileSync(templateCompilerFullPath);
144144
let templateCompilerCacheKey = crypto
145145
.createHash('md5')
146146
.update(templateCompilerContents)
147147
.digest('hex');
148148

149149
cacheData = {
150-
script: new vm.Script(templateCompilerContents, {
150+
script: new vm.Script(templateCompilerContents.toString(), {
151151
filename: templateCompilerPath,
152152
}),
153153

0 commit comments

Comments
 (0)