Mercurial > hg
changeset 49030:75794847ef62
stringutil: try to avoid running `splitlines()` only to get first line
It's wasteful to call `splitlines()` and only get the first line from
it. However, Python doesn't seem to provide a built-in way of doing
just one split based on the set of bytes used by `splitlines()`. As a
workaround, we do an initial split on just LF and then call
`splitlines()` on the result. Thanks to Joerg for this suggestion. I
didn't bother to also split on CR, so users with old Mac editors (or
repos created by such editors) will not get this performance
improvement.
Differential Revision: https://phab.mercurial-scm.org/D12413
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 25 Mar 2022 08:33:03 -0700 |
parents | eb8aed493a56 |
children | 9be7da341885 |
files | mercurial/utils/stringutil.py |
diffstat | 1 files changed, 4 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/utils/stringutil.py Thu Mar 24 22:05:49 2022 -0700 +++ b/mercurial/utils/stringutil.py Fri Mar 25 08:33:03 2022 -0700 @@ -687,6 +687,10 @@ def firstline(text): """Return the first line of the input""" + # Try to avoid running splitlines() on the whole string + i = text.find(b'\n') + if i != -1: + text = text[:i] try: return text.splitlines()[0] except IndexError: