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 b1a7338
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 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
17 changes: 5 additions & 12 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

0 comments on commit b1a7338

Please sign in to comment.