Skip to content

Commit

Permalink
Optimize handling of previous cog output
Browse files Browse the repository at this point in the history
Storing the previous cog output present in the file as a list instead of a string
  • Loading branch information
gavriil-deshaw authored and nedbat committed Mar 7, 2024
1 parent c866df0 commit ca514d7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cogapp/cogapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def processFile(self, fIn, fOut, fname=None, globals=None):

# Eat all the lines in the output section. While reading past
# them, compute the md5 hash of the old output.
previous = ""
previous = []
hasher = md5()
while l and not self.isEndOutputLine(l):
if self.isBeginSpecLine(l):
Expand All @@ -516,7 +516,7 @@ def processFile(self, fIn, fOut, fname=None, globals=None):
file=sFileIn,
line=fIn.linenumber(),
)
previous += l
previous.append(l)
hasher.update(l.encode("utf-8"))
l = fIn.readline()
curHash = hasher.hexdigest()
Expand All @@ -530,7 +530,7 @@ def processFile(self, fIn, fOut, fname=None, globals=None):
)

# Make the previous output available to the current code
self.cogmodule.previous = previous
self.cogmodule.previous = "".join(previous)

# Write the output of the spec to be the new output if we're
# supposed to generate code.
Expand Down

0 comments on commit ca514d7

Please sign in to comment.