From cb5c331d08b99a94dded8916b6130adf202548ec Mon Sep 17 00:00:00 2001 From: Wilco Fiers Date: Wed, 12 Jun 2024 14:51:33 +0200 Subject: [PATCH] perf: cache selector creation --- lib/core/utils/dq-element.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/core/utils/dq-element.js b/lib/core/utils/dq-element.js index ab259a0c47..eb87c35b57 100644 --- a/lib/core/utils/dq-element.js +++ b/lib/core/utils/dq-element.js @@ -96,7 +96,10 @@ DqElement.prototype = { * @return {String} */ get selector() { - return this.spec.selector || [getSelector(this.element, this._options)]; + if (!this.spec.selector) { + this.spec.selector = [getSelector(this.element, this._options)]; + } + return this.spec.selector; }, /** @@ -104,7 +107,10 @@ DqElement.prototype = { * @return {String} */ get ancestry() { - return this.spec.ancestry || [getAncestry(this.element)]; + if (!this.spec.ancestry) { + this.spec.ancestry = [getAncestry(this.element)]; + } + return this.spec.ancestry; }, /** @@ -112,7 +118,10 @@ DqElement.prototype = { * @return {String} */ get xpath() { - return this.spec.xpath || [getXpath(this.element)]; + if (!this.spec.xpath) { + this.spec.xpath = [getXpath(this.element)]; + } + return this.spec.xpath; }, /**