1. Shlomi Fish
  2. asciidoc

Commits

Stuart Rackham  committed 64bd4a6

Cached precompiled regular expression delimiters (speed up User Manual compile
by 250%).

  • Participants
  • Parent commits 8c4793a
  • Branches default

Comments (0)

Files changed (1)

File asciidoc.py

View file
         self.name=None      # Configuration file section name.
         # Configuration parameters.
         self.delimiter=None # Regular expression matching block delimiter.
+        self.delimiter_reo=None # Compiled delimiter.
         self.template=None  # template section entry.
         self.options=()     # options entry list.
         self.presubs=None   # presubs/subs entry list.
         result = False
         reader.skip_blank_lines()
         if reader.read_next():
-            mo = re.match(self.delimiter,reader.read_next())
+            if not self.delimiter_reo:
+                # Cache compiled delimiter optimization.
+                self.delimiter_reo = re.compile(self.delimiter)
+            mo = self.delimiter_reo.match(reader.read_next())
             if mo:
                 self.mo = mo
                 result = True
         self.current=None
         self.blocks = []        # List of Block objects.
         self.default = None     # Default Block.
-        self.delimiters = None  # Combined tables delimiter regular expression.
+        self.delimiters = None  # Combined delimiters regular expression.
     def load(self,sections):
         """Load block definition from 'sections' dictionary."""
         for k in sections.keys():