@@ -7,6 +7,7 @@ import DocTypeReader from './DocTypeReader.js';
77import toNumber from "strnum" ;
88import getIgnoreAttributesFn from "../ignoreAttributes.js" ;
99import { Expression , Matcher } from 'path-expression-matcher' ;
10+ import { ExpressionSet } from 'path-expression-matcher' ;
1011
1112// const regx =
1213// '<((!\\[CDATA\\[([\\s\\S]*?)(]]>))|((NAME:)?(NAME))([^>]*)>|((\\/)(NAME)\\s*>))([^<]*)'
@@ -121,19 +122,20 @@ export default class OrderedObjParser {
121122 this . isCurrentNodeStopNode = false ;
122123
123124 // Pre-compile stopNodes expressions
125+ this . stopNodeExpressionsSet = new ExpressionSet ( ) ;
124126 const stopNodesOpts = this . options . stopNodes ;
125127 if ( stopNodesOpts && stopNodesOpts . length > 0 ) {
126- this . stopNodeExpressions = [ ] ;
127128 for ( let i = 0 ; i < stopNodesOpts . length ; i ++ ) {
128129 const stopNodeExp = stopNodesOpts [ i ] ;
129130 if ( typeof stopNodeExp === 'string' ) {
130131 // Convert string to Expression object
131- this . stopNodeExpressions . push ( new Expression ( stopNodeExp ) ) ;
132+ this . stopNodeExpressionsSet . add ( new Expression ( stopNodeExp ) ) ;
132133 } else if ( stopNodeExp instanceof Expression ) {
133134 // Already an Expression object
134- this . stopNodeExpressions . push ( stopNodeExp ) ;
135+ this . stopNodeExpressionsSet . add ( stopNodeExp ) ;
135136 }
136137 }
138+ this . stopNodeExpressionsSet . seal ( ) ;
137139 }
138140 }
139141
@@ -494,7 +496,7 @@ const parseXml = function (xmlData) {
494496
495497 // Now check if this is a stop node (after attributes are set)
496498 if ( tagName !== xmlObj . tagname ) {
497- this . isCurrentNodeStopNode = this . isItStopNode ( this . stopNodeExpressions , this . matcher ) ;
499+ this . isCurrentNodeStopNode = this . isItStopNode ( ) ;
498500 }
499501
500502 const startIndex = i ;
@@ -727,15 +729,10 @@ function saveTextToParentTag(textData, parentNode, matcher, isLeafNode) {
727729 * @param {Array<Expression> } stopNodeExpressions - Array of compiled Expression objects
728730 * @param {Matcher } matcher - Current path matcher
729731 */
730- function isItStopNode ( stopNodeExpressions , matcher ) {
731- if ( ! stopNodeExpressions || stopNodeExpressions . length === 0 ) return false ;
732+ function isItStopNode ( ) {
733+ if ( this . stopNodeExpressionsSet . size === 0 ) return false ;
732734
733- for ( let i = 0 ; i < stopNodeExpressions . length ; i ++ ) {
734- if ( matcher . matches ( stopNodeExpressions [ i ] ) ) {
735- return true ;
736- }
737- }
738- return false ;
735+ return this . matcher . matchesAny ( this . stopNodeExpressionsSet ) ;
739736}
740737
741738/**
0 commit comments