Skip to content

Commit

Permalink
Improve rendering performance
Browse files Browse the repository at this point in the history
Avoid unnecessary copies via Utils.extend in hot paths.
  • Loading branch information
mohd-akram committed Sep 1, 2024
1 parent 7de4b41 commit 765578a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 27 deletions.
11 changes: 0 additions & 11 deletions lib/handlebars/internal/create-new-lookup-object.js

This file was deleted.

8 changes: 5 additions & 3 deletions lib/handlebars/internal/proto-access.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { createNewLookupObject } from './create-new-lookup-object';
import { extend } from '../utils';
import logger from '../logger';

const loggedProperties = Object.create(null);

export function createProtoAccessControl(runtimeOptions) {
// Create an object with "null"-prototype to avoid truthy results on
// prototype properties.
let defaultMethodWhiteList = Object.create(null);
defaultMethodWhiteList['constructor'] = false;
defaultMethodWhiteList['__defineGetter__'] = false;
Expand All @@ -16,14 +18,14 @@ export function createProtoAccessControl(runtimeOptions) {

return {
properties: {
whitelist: createNewLookupObject(
whitelist: extend(
defaultPropertyWhiteList,
runtimeOptions.allowedProtoProperties
),
defaultValue: runtimeOptions.allowProtoPropertiesByDefault
},
methods: {
whitelist: createNewLookupObject(
whitelist: extend(
defaultMethodWhiteList,
runtimeOptions.allowedProtoMethods
),
Expand Down
20 changes: 7 additions & 13 deletions lib/handlebars/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,18 @@ export function template(templateSpec, env) {
}
partial = env.VM.resolvePartial.call(this, partial, context, options);

let extendedOptions = Utils.extend({}, options, {
hooks: this.hooks,
protoAccessControl: this.protoAccessControl
});

let result = env.VM.invokePartial.call(
this,
partial,
context,
extendedOptions
);
options.hooks = this.hooks;
options.protoAccessControl = this.protoAccessControl;

let result = env.VM.invokePartial.call(this, partial, context, options);

if (result == null && env.compile) {
options.partials[options.name] = env.compile(
partial,
templateSpec.compilerOptions,
env
);
result = options.partials[options.name](context, extendedOptions);
result = options.partials[options.name](context, options);
}
if (result != null) {
if (options.indent) {
Expand Down Expand Up @@ -438,6 +431,7 @@ function wrapHelpersToPassLookupProperty(mergedHelpers, container) {
function passLookupPropertyOption(helper, container) {
const lookupProperty = container.lookupProperty;
return wrapHelper(helper, options => {
return Utils.extend({ lookupProperty }, options);
options.lookupProperty = lookupProperty;
return options;
});
}

0 comments on commit 765578a

Please sign in to comment.