diff options
author | Ghostkeeper <ghost_keeper+github@hotmail.com> | 2015-12-16 17:13:13 +0300 |
---|---|---|
committer | Ghostkeeper <ghost_keeper+github@hotmail.com> | 2015-12-17 15:35:16 +0300 |
commit | 6908f2c0117ec2d1f73539a365947da12f86c3d7 (patch) | |
tree | a7d3ad29c292202354794fc5c87c10e4eb9d3e87 /plugins/GCodeProfileReader | |
parent | cfa43820527d7c4fa29c1ecf2dfef753ee7e23bf (diff) |
Move prefix length out of for loop
It is cached so it only needs to be computed once.
Contributes to issue CURA-34.
Diffstat (limited to 'plugins/GCodeProfileReader')
-rw-r--r-- | plugins/GCodeProfileReader/GCodeProfileReader.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/plugins/GCodeProfileReader/GCodeProfileReader.py b/plugins/GCodeProfileReader/GCodeProfileReader.py index 524e4662d5..ed37e93a18 100644 --- a/plugins/GCodeProfileReader/GCodeProfileReader.py +++ b/plugins/GCodeProfileReader/GCodeProfileReader.py @@ -30,14 +30,15 @@ class GCodeProfileReader(ProfileReader): # None \endcode is returned. def read(self, file_name): prefix = ";SETTING_" + str(version) + " " - + prefix_length = len(prefix) + #Loading all settings from the file. They are all at the end, but Python has no reverse seek any more since Python3. TODO: Consider moving settings to the start? serialised = "" #Will be filled with the serialised profile. try: with open(file_name) as f: for line in f: if line.startswith(prefix): - serialised += line[len(prefix):-1] #Remove the prefix and the newline from the line, and add it to the rest. + serialised += line[prefix_length : -1] #Remove the prefix and the newline from the line, and add it to the rest. except IOError as e: Logger.log("e", "Unable to open file %s for reading: %s", file_name, str(e)) return None |