mirror of
https://gitlab.winehq.org/wine/wine-staging.git
synced 2024-11-21 16:46:54 -08:00
patchutils.py: Speed improvement for hunk parsing (approximately by a factor of 2).
We don't need to keep the whole line in memory, the first character is sufficient. Moreover, exception handling is faster in python than explicitly checking for None.
This commit is contained in:
parent
92fc5f6141
commit
f66b06739e
43
debian/tools/patchutils.py
vendored
43
debian/tools/patchutils.py
vendored
@ -218,27 +218,28 @@ def read_patch(filename):
|
||||
raise PatchParserError("Empty hunk doesn't make sense.")
|
||||
assert fp.read() == line
|
||||
|
||||
while srclines > 0 or dstlines > 0:
|
||||
line = fp.read()
|
||||
if line is None:
|
||||
raise PatchParserError("Truncated patch.")
|
||||
elif line.startswith(" "):
|
||||
if srclines == 0 or dstlines == 0:
|
||||
raise PatchParserError("Corrupted patch.")
|
||||
srclines -= 1
|
||||
dstlines -= 1
|
||||
elif line.startswith("-"):
|
||||
if srclines == 0:
|
||||
raise PatchParserError("Corrupted patch.")
|
||||
srclines -= 1
|
||||
elif line.startswith("+"):
|
||||
if dstlines == 0:
|
||||
raise PatchParserError("Corrupted patch.")
|
||||
dstlines -= 1
|
||||
elif line.startswith("\\ "):
|
||||
pass # ignore
|
||||
else:
|
||||
raise PatchParserError("Unexpected line in hunk.")
|
||||
try:
|
||||
while srclines > 0 or dstlines > 0:
|
||||
line = fp.read()[0]
|
||||
if line == " ":
|
||||
if srclines == 0 or dstlines == 0:
|
||||
raise PatchParserError("Corrupted patch.")
|
||||
srclines -= 1
|
||||
dstlines -= 1
|
||||
elif line == "-":
|
||||
if srclines == 0:
|
||||
raise PatchParserError("Corrupted patch.")
|
||||
srclines -= 1
|
||||
elif line == "+":
|
||||
if dstlines == 0:
|
||||
raise PatchParserError("Corrupted patch.")
|
||||
dstlines -= 1
|
||||
elif line == "\\":
|
||||
pass # ignore
|
||||
else:
|
||||
raise PatchParserError("Unexpected line in hunk.")
|
||||
except TypeError: # triggered by None[0]
|
||||
raise PatchParserError("Truncated patch.")
|
||||
|
||||
while True:
|
||||
line = fp.peek()
|
||||
|
Loading…
Reference in New Issue
Block a user