perf(compiler-core): add perf optimization to parseText (#458)

This commit is contained in:
Gabriel Loiácono 2019-11-15 19:48:01 -03:00 committed by Evan You
parent 353b06df77
commit 2780e0df4c

View File

@ -767,16 +767,19 @@ function parseInterpolation(
function parseText(context: ParserContext, mode: TextModes): TextNode { function parseText(context: ParserContext, mode: TextModes): TextNode {
__TEST__ && assert(context.source.length > 0) __TEST__ && assert(context.source.length > 0)
const [open] = context.options.delimiters const endTokens = ['<', context.options.delimiters[0]]
// TODO could probably use some perf optimization if (mode === TextModes.CDATA) {
const endIndex = Math.min( endTokens.push(']]>')
...[ }
context.source.indexOf('<', 1),
context.source.indexOf(open, 1), let endIndex = context.source.length
mode === TextModes.CDATA ? context.source.indexOf(']]>') : -1, for (let i = 0; i < endTokens.length; i++) {
context.source.length const index = context.source.indexOf(endTokens[i], 1)
].filter(n => n !== -1) if (index !== -1 && endIndex > index) {
) endIndex = index
}
}
__TEST__ && assert(endIndex > 0) __TEST__ && assert(endIndex > 0)
const start = getCursor(context) const start = getCursor(context)