1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-19 00:17:51 +02:00

Revert "Simplify process() in history.py, avoid list allocation in parse()"

This commit is contained in:
Kelly Brazil
2020-03-04 15:32:23 -08:00
committed by GitHub
parent d75c4068ca
commit c01bcd3734

View File

@ -79,11 +79,21 @@ def process(proc_data):
# rebuild output for added semantic information
processed = []
for k, v in proc_data.items():
proc_line = {
'line': int(k) if k.isdigit() else None,
'command': v,
}
proc_line = {}
proc_line['line'] = k
proc_line['command'] = v
processed.append(proc_line)
for entry in processed:
int_list = ['line']
for key in int_list:
if key in entry:
try:
key_int = int(entry[key])
entry[key] = key_int
except (ValueError):
entry[key] = None
return processed
@ -110,8 +120,11 @@ def parse(data, raw=False, quiet=False):
# split lines and clear out any non-ascii chars
linedata = data.encode('ascii', errors='ignore').decode().splitlines()
# Skip any blank lines
for entry in filter(None, linedata):
# Clear any blank lines
cleandata = list(filter(None, linedata))
if cleandata:
for entry in cleandata:
try:
parsed_line = entry.split(maxsplit=1)
raw_output[parsed_line[0]] = parsed_line[1]