Skip to content

Commit

Permalink
Fix/Improve ObjC Syntax Highlighting Multithreading
Browse files Browse the repository at this point in the history
  • Loading branch information
KritantaDev authored and KritantaDev committed Jan 6, 2022
1 parent fdd7649 commit 9572cc3
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/ktool/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1575,8 +1575,8 @@ def load_cmds(lib, parent=None, callback=None):

@staticmethod
def symtab(lib, parent=None, callback=None):
mmci = MainMenuContentItem()
callback(f'Slice {KToolMachOLoader.CUR_SL}/{KToolMachOLoader.SL_CNT}\nProcessing Symtab')
mmci = MainMenuContentItem()
tab = Table()
tab.titles = ['Address', 'Name']
for sym in lib.symbol_table.table:
Expand Down Expand Up @@ -1643,14 +1643,13 @@ def exports(lib, parent=None, callback=None):
return menuitem

@staticmethod
def get_header_item(text, name, menuitem):
def get_header_item(text, name):
mmci = MainMenuContentItem()
formatter = Terminal256Formatter() if KToolMachOLoader.SUPPORTS_256 else TerminalFormatter()
text = highlight(text, ObjectiveCLexer(), formatter)
lines = text.split('\n')
mmci.lines = lines
h_menu_item = SidebarMenuItem(name, mmci, menuitem)
h_menu_item.parse_mmc()
h_menu_item = SidebarMenuItem(name, mmci, None)
return h_menu_item

@staticmethod
Expand All @@ -1661,15 +1660,22 @@ def objc_headers(objc_lib, parent=None, callback=None):
menuitem = SidebarMenuItem("ObjC Headers", hnci, parent)
count = len(generator.headers.keys())
i = 1
callback(f'Slice {KToolMachOLoader.CUR_SL}/{KToolMachOLoader.SL_CNT}\nProcessing {count} ObjC Headers')
callback(f'Slice {KToolMachOLoader.CUR_SL}/{KToolMachOLoader.SL_CNT}\nProcessing {count} ObjC Headers\nInitial Syntax Highlighting')
futures = []

with concurrent.futures.ProcessPoolExecutor(max_workers=THREAD_COUNT) as executor:
for header_name, header in generator.headers.items():
futures.append(executor.submit(KToolMachOLoader.get_header_item, header.text, header_name, menuitem))
futures.append(executor.submit(KToolMachOLoader.get_header_item, str(header.text), str(header_name)))
i += 1
items = [f.result() for f in futures]
callback(f'Slice {KToolMachOLoader.CUR_SL}/{KToolMachOLoader.SL_CNT}\nProcessing {count} ObjC Headers\nRendering color schema')
for item in items:
item.parent = menuitem
with concurrent.futures.ThreadPoolExecutor(max_workers=THREAD_COUNT) as executor:
futures.append(executor.submit(item.parse_mmc))

menuitem.children = [f.result() for f in futures]
[f.result() for f in futures]
menuitem.children = items

menuitem.parse_mmc()
return menuitem
Expand Down

0 comments on commit 9572cc3

Please sign in to comment.