Skip to content

Commit 93cd838

Browse files
gkelloggdavidlehn
authored andcommitted
Reduce computational complexity of normalizing value/type/language in _valueMatch.
1 parent 5c4f267 commit 93cd838

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lib/frame.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,15 @@ function _valueMatch(pattern, value) {
603603
const v1 = value['@value'];
604604
const t1 = value['@type'];
605605
const l1 = value['@language'];
606-
const v2 = pattern['@value'] ? [].concat(pattern['@value']) : [];
607-
const t2 = pattern['@type'] ? [].concat(pattern['@type']) : [];
608-
const l2 = pattern['@language'] ? [].concat(pattern['@language']) : [];
606+
const v2 = pattern['@value'] ?
607+
(types.isArray(pattern['@value']) ? pattern['@value'] : [pattern['@value']]) :
608+
[];
609+
const t2 = pattern['@type'] ?
610+
(types.isArray(pattern['@type']) ? pattern['@type'] : [pattern['@type']]) :
611+
[];
612+
const l2 = pattern['@language'] ?
613+
(types.isArray(pattern['@language']) ? pattern['@language'] : [pattern['@language']]) :
614+
[];
609615

610616
if(v2.length === 0 && t2.length === 0 && l2.length === 0) {
611617
return true;

0 commit comments

Comments
 (0)