Skip to content
Snippets Groups Projects
Unverified Commit 51d99925 authored by mirabilos's avatar mirabilos Committed by mirabilos
Browse files

cache line.strip() to speed up reading

parent 0f2fe94e
No related branches found
No related tags found
No related merge requests found
......@@ -53,14 +53,15 @@ def mml_file(path, _play=None, _barline=None, _mmltrk=None):
with codecs.open(path, "r", "UTF-8") as mmlfile:
for line in mmlfile:
if line.strip().startswith("#"):
line = line.strip()
if line.startswith("#"):
continue
elif line.strip() == "":
elif line == "":
vcount = 0
else:
if len(vstrings) <= vcount:
vstrings.append("")
vstrings[vcount] += line.strip()
vstrings[vcount] += line
vcount += 1
for vstring in vstrings:
......@@ -82,24 +83,25 @@ def mml_file_meta(path):
with codecs.open(path, "r", "UTF-8") as mmlfile:
for line in mmlfile:
line = line.strip()
if state == 0:
# Header fields
if line.strip() == "":
if line == "":
state = 1
elif line.strip().startswith("# ") and ":" in line:
parts = line.strip()[1:].split(":")
elif line.startswith("# ") and ":" in line:
parts = line[1:].split(":")
key = str(parts.pop(0))
value = ":".join(parts)
meta[key.strip().lower()] = value.strip()
if state == 1:
# Skip first empty line (header/body separator)
if not line.strip() == "":
if not line == "":
state = 2
if state == 2:
if line.strip().startswith("#"):
if line.startswith("#"):
continue
if line.strip() == "":
if line == "":
if not vcount:
# comment block preceding music
continue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment