Move prefix length out of for loop

It is cached so it only needs to be computed once.

Contributes to issue CURA-34.
This commit is contained in:
Ghostkeeper 2015-12-16 15:13:13 +01:00
parent cfa4382052
commit 6908f2c011
2 changed files with 7 additions and 5 deletions

View file

@ -15,7 +15,7 @@ class GCodeWriter(MeshWriter):
# written with. If the file format is changed in a way that breaks reverse
# compatibility, increment this version number!
version = 1
def __init__(self):
super().__init__()
@ -44,6 +44,7 @@ class GCodeWriter(MeshWriter):
# \return A serialised string of the profile.
def _serialiseProfile(self, profile):
prefix = ";SETTING_" + str(version) + " " #The prefix to put before each line.
prefix_length = len(prefix)
serialised = profile.serialise()
@ -60,8 +61,8 @@ class GCodeWriter(MeshWriter):
#Introduce line breaks so that each comment is no longer than 80 characters. Prepend each line with the prefix.
result = ""
for pos in range(0, len(serialised), 80 - len(prefix)): #Lines have 80 characters, so the payload of each line is 80 - prefix.
result += prefix + serialised[pos : pos + 80 - len(prefix)] + "\n"
for pos in range(0, len(serialised), 80 - prefix_length): #Lines have 80 characters, so the payload of each line is 80 - prefix.
result += prefix + serialised[pos : pos + 80 - prefix_length] + "\n"
serialised = result
return serialised