Don't lock up on very long lined documents

This commit is contained in:
James Allen 2015-08-28 16:51:52 +01:00
parent 0aaeb6671e
commit 40704b486e

View file

@ -15,8 +15,12 @@ module.exports = ProjectRootDocManager =
return (cb)->
rootDocId = null
for line in doc.lines || []
match = line.match /(.*)\\documentclass/ # no lookbehind in js regexp :(
isRootDoc = Path.extname(path).match(/\.R?tex$/) and match and !match[1].match /%/
# We've had problems with this regex locking up CPU.
# Previously /.*\\documentclass/ would totally lock up on lines of 500kb (data text files :()
# This regex will only look from the start of the line, including whitespace so will return quickly
# regardless of line length.
match = line.match /^\s*\\documentclass/
isRootDoc = Path.extname(path).match(/\.R?tex$/) and match
if isRootDoc
rootDocId = doc?._id
cb(rootDocId)