mirror of
https://github.com/isledecomp/isle.git
synced 2026-01-22 15:51:16 +00:00
reccmp: avoid repeated execution of winepath
Executing winepath many times is slow, so try we like to avoid it as much as possible. When the path start with a known prefix, replace it with a cached prefix and do some string manipulation. This change reduces execution time of reccmp.py from 90s to 2s. Which is nice. m
This commit is contained in:
parent
8476bf06b2
commit
11ffd576c5
@ -90,16 +90,38 @@ def read(self, offset, size):
|
|||||||
return self.file.read(size)
|
return self.file.read(size)
|
||||||
|
|
||||||
class RecompiledInfo:
|
class RecompiledInfo:
|
||||||
addr = None
|
def __init__(self):
|
||||||
size = None
|
self.addr = None
|
||||||
name = None
|
self.size = None
|
||||||
start = None
|
self.name = None
|
||||||
|
self.start = None
|
||||||
|
|
||||||
def get_wine_path(fn):
|
class WinePathConverter:
|
||||||
return subprocess.check_output(['winepath', '-w', fn]).decode('utf-8').strip()
|
def __init__(self, unix_cwd):
|
||||||
|
self.unix_cwd = unix_cwd
|
||||||
|
self.win_cwd = self._call_winepath_unix2win(self.unix_cwd)
|
||||||
|
|
||||||
def get_unix_path(fn):
|
def get_wine_path(self, unix_fn: str) -> str:
|
||||||
return subprocess.check_output(['winepath', fn]).decode('utf-8').strip()
|
if unix_fn.startswith('./'):
|
||||||
|
return self.win_cmd + '\\' + unix_fn[2:].replace('/', '\\')
|
||||||
|
if unix_fn.startswith(self.unix_cwd):
|
||||||
|
return self.win_cwd + '\\' + unix_fn.removeprefix(self.unix_cwd).replace('/', '\\').lstrip('\\')
|
||||||
|
return self._call_winepath_unix2win(unix_fn)
|
||||||
|
|
||||||
|
def get_unix_path(self, win_fn: str) -> str:
|
||||||
|
if win_fn.startswith('.\\') or win_fn.startswith('./'):
|
||||||
|
return self.unix_cwd + '/' + win_fn[2:].replace('\\', '/')
|
||||||
|
if win_fn.startswith(self.win_cwd):
|
||||||
|
return self.unix_cwd + '/' + win_fn.removeprefix(self.win_cwd).replace('\\', '/')
|
||||||
|
return self._call_winepath_win2unix(win_fn)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _call_winepath_unix2win(fn: str) -> str:
|
||||||
|
return subprocess.check_output(['winepath', '-w', fn], text=True).strip()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _call_winepath_win2unix(fn: str) -> str:
|
||||||
|
return subprocess.check_output(['winepath', fn], text=True).strip()
|
||||||
|
|
||||||
def get_file_in_script_dir(fn):
|
def get_file_in_script_dir(fn):
|
||||||
return os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), fn)
|
return os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])), fn)
|
||||||
@ -109,13 +131,13 @@ class SymInfo:
|
|||||||
funcs = {}
|
funcs = {}
|
||||||
lines = {}
|
lines = {}
|
||||||
|
|
||||||
def __init__(self, pdb, file):
|
def __init__(self, pdb, file, wine_path_converter):
|
||||||
call = [get_file_in_script_dir('cvdump.exe'), '-l', '-s']
|
call = [get_file_in_script_dir('cvdump.exe'), '-l', '-s']
|
||||||
|
|
||||||
if os.name != 'nt':
|
if wine_path_converter:
|
||||||
# Run cvdump through wine and convert path to Windows-friendly wine path
|
# Run cvdump through wine and convert path to Windows-friendly wine path
|
||||||
call.insert(0, 'wine')
|
call.insert(0, 'wine')
|
||||||
call.append(get_wine_path(pdb))
|
call.append(wine_path_converter.get_wine_path(pdb))
|
||||||
else:
|
else:
|
||||||
call.append(pdb)
|
call.append(pdb)
|
||||||
|
|
||||||
@ -155,9 +177,9 @@ def __init__(self, pdb, file):
|
|||||||
elif current_section == 'LINES' and line.startswith(' ') and not line.startswith(' '):
|
elif current_section == 'LINES' and line.startswith(' ') and not line.startswith(' '):
|
||||||
sourcepath = line.split()[0]
|
sourcepath = line.split()[0]
|
||||||
|
|
||||||
if os.name != 'nt':
|
if wine_path_converter:
|
||||||
# Convert filename to Unix path for file compare
|
# Convert filename to Unix path for file compare
|
||||||
sourcepath = get_unix_path(sourcepath)
|
sourcepath = wine_path_converter.get_unix_path(sourcepath)
|
||||||
|
|
||||||
if sourcepath not in self.lines:
|
if sourcepath not in self.lines:
|
||||||
self.lines[sourcepath] = {}
|
self.lines[sourcepath] = {}
|
||||||
@ -201,9 +223,12 @@ def get_recompiled_address(self, filename, line):
|
|||||||
else:
|
else:
|
||||||
print('Failed to find function symbol with filename and line: %s:%s' % (filename, str(line)))
|
print('Failed to find function symbol with filename and line: %s:%s' % (filename, str(line)))
|
||||||
|
|
||||||
|
wine_path_converter = None
|
||||||
|
if os.name != 'nt':
|
||||||
|
wine_path_converter = WinePathConverter(source)
|
||||||
origfile = Bin(original)
|
origfile = Bin(original)
|
||||||
recompfile = Bin(recomp)
|
recompfile = Bin(recomp)
|
||||||
syminfo = SymInfo(syms, recompfile)
|
syminfo = SymInfo(syms, recompfile, wine_path_converter)
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user