Patchwork histedit: Speed up scrolling in patch view mode

login
register
mail settings
Submitter Yu Feng
Date April 25, 2019, 10:31 p.m.
Message ID <458dc948aff9f1217718.1556231507@feyu.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/39835/
State New
Headers show

Comments

Yu Feng - April 25, 2019, 10:31 p.m.
# HG changeset patch
# User feyu@google.com
# Date 1556231440 25200
#      Thu Apr 25 15:30:40 2019 -0700
# Node ID 458dc948aff9f1217718b7679f890fea510d54f7
# Parent  d6d86496b7bc2c8120973e148f86a64aec75a25a
histedit: Speed up scrolling in patch view mode

Store patchcontents into the mode state, avoiding the expensive
call to ui for computing the patchcontents.

Before this change in large repos histedit patch view mode can
be very irresponsive.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1079,6 +1079,8 @@  def movecursor(state, oldpos, newpos):
 def changemode(state, mode):
     curmode, _ = state['mode']
     state['mode'] = (mode, curmode)
+    if mode == MODE_PATCH:
+        state['modes'][MODE_PATCH]['patchcontents'] = patchcontents(state)
 
 def makeselection(state, pos):
     state['selected'] = pos
@@ -1134,7 +1136,7 @@  def changeview(state, delta, unit):
     if mode != MODE_PATCH:
         return
     mode_state = state['modes'][mode]
-    num_lines = len(patchcontents(state))
+    num_lines = len(mode_state['patchcontents'])
     page_height = state['page_height']
     unit = page_height if unit == 'page' else 1
     num_pages = 1 + (num_lines - 1) / page_height
@@ -1392,7 +1394,8 @@  pgup/K: move patch up, pgdn/J: move patc
 
     def renderpatch(win, state):
         start = state['modes'][MODE_PATCH]['line_offset']
-        renderstring(win, state, patchcontents(state)[start:], diffcolors=True)
+        content = state['modes'][MODE_PATCH]['patchcontents']
+        renderstring(win, state, content[start:], diffcolors=True)
 
     def layout(mode):
         maxy, maxx = stdscr.getmaxyx()