Skip to content

Commit

Permalink
perf(compiler-core): add perf optimization to parseText (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
loiacon authored and yyx990803 committed Nov 15, 2019
1 parent 353b06d commit 2780e0d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/compiler-core/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,16 +767,19 @@ function parseInterpolation(
function parseText(context: ParserContext, mode: TextModes): TextNode {
__TEST__ && assert(context.source.length > 0)

const [open] = context.options.delimiters
// TODO could probably use some perf optimization
const endIndex = Math.min(
...[
context.source.indexOf('<', 1),
context.source.indexOf(open, 1),
mode === TextModes.CDATA ? context.source.indexOf(']]>') : -1,
context.source.length
].filter(n => n !== -1)
)
const endTokens = ['<', context.options.delimiters[0]]
if (mode === TextModes.CDATA) {
endTokens.push(']]>')
}

let endIndex = context.source.length
for (let i = 0; i < endTokens.length; i++) {
const index = context.source.indexOf(endTokens[i], 1)
if (index !== -1 && endIndex > index) {
endIndex = index
}
}

__TEST__ && assert(endIndex > 0)

const start = getCursor(context)
Expand Down

0 comments on commit 2780e0d

Please sign in to comment.