changelog: parse description last
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 06 Mar 2016 13:13:54 -0800
changeset 30729 63653147e9bb26550cbe46d5a1bdf961471af0e5
parent 30728 7796473c11b3b0c132bea567a4660626cb57fdb2
child 30730 70c2f8a982766b512e9d7f41f2d93fdb92f5481f
push id200
push usergszorc@mozilla.com
push dateSat, 12 Mar 2016 00:54:44 +0000
changelog: parse description last Before, we first searched for the double newline as the first step in the parse then moved to the front of the string and worked our way to the back again. This made sense when we were splitting the raw text on the double newline. But in our new newline scanning based approach, this feels awkward. This patch updates the parsing logic to parse the text linearly and deal with the description field last. Because we're avoiding an extra string scan, revsets appear to demonstrate a very slight performance win. But the percentage change is marginal, so the numbers aren't worth reporting.
mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -179,34 +179,34 @@ class changelogrevision(object):
         # time tz extra\n : date (time is int or float, timezone is int)
         #                 : extra is metadata, encoded and separated by '\0'
         #                 : older versions ignore it
         # files\n\n       : files modified by the cset, no \n or \r allowed
         # (.*)            : comment (free text, ideally utf-8)
         #
         # changelog v0 doesn't use extra
 
-        doublenl = text.index('\n\n')
-        self._rawdesc = text[doublenl + 2:]
-
         nl1 = text.index('\n')
         self._rawmanifest = text[0:nl1]
 
         nl2 = text.index('\n', nl1 + 1)
         self._rawuser = text[nl1 + 1:nl2]
 
         nl3 = text.index('\n', nl2 + 1)
         self._rawdateextra = text[nl2 + 1:nl3]
 
         # The list of files may be empty. Which means nl3 is the first of the
         # double newline that precedes the description.
-        if nl3 == doublenl:
+        if text[nl3 + 1] == '\n':
             self._rawfiles = None
+            self._rawdesc = text[nl3 + 2:]
         else:
+            doublenl = text.index('\n\n', nl3 + 1)
             self._rawfiles = text[nl3 + 1:doublenl]
+            self._rawdesc = text[doublenl + 2:]
 
         return self
 
     @property
     def manifest(self):
         return bin(self._rawmanifest)
 
     @property