comparison hgext/histedit.py @ 42234:c4a50e863ee2

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.
author feyu@google.com
date Thu, 25 Apr 2019 15:30:40 -0700
parents 4ad191041be2
children 5f2f6912c9e6
comparison
equal deleted inserted replaced
42233:4ad191041be2 42234:c4a50e863ee2
1077 state['modes'][MODE_PATCH]['line_offset'] = 0 1077 state['modes'][MODE_PATCH]['line_offset'] = 0
1078 1078
1079 def changemode(state, mode): 1079 def changemode(state, mode):
1080 curmode, _ = state['mode'] 1080 curmode, _ = state['mode']
1081 state['mode'] = (mode, curmode) 1081 state['mode'] = (mode, curmode)
1082 if mode == MODE_PATCH:
1083 state['modes'][MODE_PATCH]['patchcontents'] = patchcontents(state)
1082 1084
1083 def makeselection(state, pos): 1085 def makeselection(state, pos):
1084 state['selected'] = pos 1086 state['selected'] = pos
1085 1087
1086 def swap(state, oldpos, newpos): 1088 def swap(state, oldpos, newpos):
1132 changesets). 'delta' is an amount (+/- 1) and 'unit' is 'page' or 'line'.''' 1134 changesets). 'delta' is an amount (+/- 1) and 'unit' is 'page' or 'line'.'''
1133 mode, _ = state['mode'] 1135 mode, _ = state['mode']
1134 if mode != MODE_PATCH: 1136 if mode != MODE_PATCH:
1135 return 1137 return
1136 mode_state = state['modes'][mode] 1138 mode_state = state['modes'][mode]
1137 num_lines = len(patchcontents(state)) 1139 num_lines = len(mode_state['patchcontents'])
1138 page_height = state['page_height'] 1140 page_height = state['page_height']
1139 unit = page_height if unit == 'page' else 1 1141 unit = page_height if unit == 'page' else 1
1140 num_pages = 1 + (num_lines - 1) / page_height 1142 num_pages = 1 + (num_lines - 1) / page_height
1141 max_offset = (num_pages - 1) * page_height 1143 max_offset = (num_pages - 1) * page_height
1142 newline = mode_state['line_offset'] + delta * unit 1144 newline = mode_state['line_offset'] + delta * unit
1392 win.addstr(y, 0, line) 1394 win.addstr(y, 0, line)
1393 win.noutrefresh() 1395 win.noutrefresh()
1394 1396
1395 def renderpatch(win, state): 1397 def renderpatch(win, state):
1396 start = state['modes'][MODE_PATCH]['line_offset'] 1398 start = state['modes'][MODE_PATCH]['line_offset']
1397 renderstring(win, state, patchcontents(state)[start:], diffcolors=True) 1399 content = state['modes'][MODE_PATCH]['patchcontents']
1400 renderstring(win, state, content[start:], diffcolors=True)
1398 1401
1399 def layout(mode): 1402 def layout(mode):
1400 maxy, maxx = stdscr.getmaxyx() 1403 maxy, maxx = stdscr.getmaxyx()
1401 helplen = len(helplines(mode)) 1404 helplen = len(helplines(mode))
1402 return { 1405 return {