Просмотр исходного кода

Don't lock up on very long lined documents

James Allen 11 лет назад
Родитель
Сommit
40704b486e
1 измененных файлов с 6 добавлено и 2 удалено
  1. 6 2
      services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee

+ 6 - 2
services/web/app/coffee/Features/Project/ProjectRootDocManager.coffee

@@ -15,8 +15,12 @@ module.exports = ProjectRootDocManager =
 				return (cb)->
 				return (cb)->
 					rootDocId = null
 					rootDocId = null
 					for line in doc.lines || []
 					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
 						if isRootDoc
 							rootDocId = doc?._id
 							rootDocId = doc?._id
 					cb(rootDocId)
 					cb(rootDocId)