From 1a15adc3e0f205ef154cc67a8cfd68f1c26879b4 Mon Sep 17 00:00:00 2001 From: Siddharth Agarwal Date: Thu, 9 Apr 2015 20:14:33 -0700 Subject: [PATCH] git_handler.load_map: avoid split and strip For a mapfile with 1.5 million entries, this speeds up load_map from 2.3 seconds to 1.8. --- hggit/git_handler.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hggit/git_handler.py b/hggit/git_handler.py index 8a267ae9d6..1b0a4593ef 100644 --- a/hggit/git_handler.py +++ b/hggit/git_handler.py @@ -173,7 +173,13 @@ class GitHandler(object): map_hg_real = {} if os.path.exists(self.repo.join(self.map_file)): for line in self.repo.opener(self.map_file): - gitsha, hgsha = line.strip().split(' ', 1) + # format is <40 hex digits> <40 hex digits>\n + if len(line) != 82: + raise ValueError( + _('corrupt mapfile: incorrect line length %d') % + len(line)) + gitsha = line[:40] + hgsha = line[41:81] map_git_real[gitsha] = hgsha map_hg_real[hgsha] = gitsha self._map_git_real = map_git_real