Commits

step...@a60eed84-fc3d-0410-a09c-0d1a7a6707c9  committed dab9b3e

optimized macro regexp

  • Participants
  • Parent commits a59a5e7

Comments (0)

Files changed (2)

File creoleparser/elements.py

 
 BLOCK_TAGS = BLOCK_ONLY_TAGS + ['ins','del','script']
 
-
-MACRO_NAME = r'(?P<name>[a-zA-Z]+([-.]?[a-zA-Z0-9]+)*)'
+MACRO_NAME = r'(?P<name>[a-zA-Z][a-zA-Z0-9]*([-.][a-zA-Z0-9]+)*)'
 """allows any number of non-repeating hyphens or periods.
 Underscore is not included because hyphen is"""
 

File creoleparser/tests.py

 import urllib
 import unittest
 import re
+import timeit
 
 from genshi import builder
 from genshi.core import Markup
             self.parse("<<span a=1>>This is bad<</span>>"),
                        wrap_result("""<code class="macro_error">Macro error: 'span' got an unexpected keyword argument 'a'</code>"""))
 
+    def test_slow_reg_exp(self):
+        t = timeit.Timer('text2html("<<aaaaaaaaaaaaaaaaa>>")','from __main__ import text2html')
+        self.assertTrue(t.timeit(number=10) < 0.05)
+
 class InterWikiLinksTest(unittest.TestCase,BaseTest):
 
     def setUp(self):