all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#20230: 24.4.91; slow regexp
@ 2015-03-30 14:46 Nicolas Richard
  2016-06-26 18:49 ` bug#20230: Bug #20230: " Noam Postavsky
  0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Richard @ 2015-03-30 14:46 UTC (permalink / raw)
  To: 20230

Consider this snippet:

(with-temp-buffer
  (insert "**** foo\n")
  (insert ":PROPERTIES:\n")
  (dotimes (_ 7) (insert ":a:     \n"))
  (insert ":bar: foo\n\n:END:")
  (goto-char 10) ;; beginning of second line
  (looking-at "^[ 	]*:PROPERTIES:[ 	]*
\\(?:[ 	]*:\\S-+:\\(?: .*\\)?[ 	]*
\\)*[ 	]*:END:[ 	]*$"))

If that doesn't take several seconds, increasing the number 7 to 8, 9 or
more probably will. It does for me.

The regexp is one from org mode.

(It was suggested that a file this as a separate bug report in
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=20191#28)

-- 
Nicolas





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#20230: Bug #20230: 24.4.91; slow regexp
  2015-03-30 14:46 bug#20230: 24.4.91; slow regexp Nicolas Richard
@ 2016-06-26 18:49 ` Noam Postavsky
  0 siblings, 0 replies; 2+ messages in thread
From: Noam Postavsky @ 2016-06-26 18:49 UTC (permalink / raw)
  To: 20230; +Cc: Nicolas Richard

merge 6640 20230
quit

Same problem as http://debbugs.gnu.org/cgi/bugreport.cgi?bug=6640:
Emacs uses backtracking regexp engine, so when then you have a failing
regexp with repeated sub-parts that can match in many different ways,
you hit exponential behaviour. In this case

\\(?: .*\\)?[ ]*

can match a stretch of n spaces in n different ways, and since that
part is itself inside a * repetition, each those n ways has to be
tried on each line giving n^L runtime (where L is number of lines). A
faster regexp which should match the same is

  (looking-at "^[ \t]*:PROPERTIES:[ \t]*
\\(?:[ \t]*:\\S-+:[^\n]*
\\)*[ \t]*:END:[ \t]*$")





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-06-26 18:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-30 14:46 bug#20230: 24.4.91; slow regexp Nicolas Richard
2016-06-26 18:49 ` bug#20230: Bug #20230: " Noam Postavsky

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.