branch: elpa/d-mode
commit 14e2e3bf85cd9cb7db3e7d524a66cdbdccda2d91
Author: Vladimir Panteleev <[email protected]>
Commit: Vladimir Panteleev <[email protected]>

    Fix exponential fontification time of backslashes in WYSIWYG-literals
    
    Fixes issue #64
    
    Changes the regex introduced in #22 as follows:
    - Move the first non-\ character set outside of the repeated group.
      As there is an identical character set at the end of the repeated
      group, this was redundant, and the main cause of the slowdown.
    - Exclude the \ character from the character set excluding `.
      This was also causing fontification to take an exponential time,
      to a lesser degree.
    - Use non-greedy matching, which should generally perform better than
      greedy matching.
    
    Test file included, though it only tests for fontification time,
    not resulting syntax.
---
 d-mode-test.el | 1 +
 d-mode.el      | 2 +-
 tests/I0064.d  | 5 +++++
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/d-mode-test.el b/d-mode-test.el
index cb5fcfc..1347254 100644
--- a/d-mode-test.el
+++ b/d-mode-test.el
@@ -214,6 +214,7 @@
 (ert-deftest d-mode-basic ()
   (should (equal (do-one-test "tests/I0021.d") t))
   (should (equal (do-one-test "tests/I0039.d") t))
+  (should (equal (do-one-test "tests/I0064.d") t))
   )
 
 ;;----------------------------------------------------------------------------
diff --git a/d-mode.el b/d-mode.el
index e043237..ccf398b 100644
--- a/d-mode.el
+++ b/d-mode.el
@@ -542,7 +542,7 @@ Key bindings:
   ;; syntax-propertize-rules function for more information.
   (when (version<= "24.3" emacs-version)
     (setq-local syntax-propertize-function
-                (syntax-propertize-rules ("`\\([^`]*\\(\\\\\\)[^`]*\\)+`" (2 
"."))))))
+                (syntax-propertize-rules 
("`[^\\\\`]*?\\(\\(\\\\\\)[^\\\\`]*?\\)+?`" (2 "."))))))
 
 ;;----------------------------------------------------------------------------
 ;; "Hideous hacks" to support appropriate font-lock behaviour.
diff --git a/tests/I0064.d b/tests/I0064.d
new file mode 100644
index 0000000..3457c13
--- /dev/null
+++ b/tests/I0064.d
@@ -0,0 +1,5 @@
+`\`aoeu
+`\\`aoeu
+
+`\\aaa\\aaa\\aaa\\aaa`
+`\\aaa\\aaa\\aaa\\aaa

Reply via email to