summaryrefslogtreecommitdiffstats
path: root/parsers
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2021-12-19 14:24:20 +0000
committerPhilip Sargent <philip.sargent@gmail.com>2021-12-19 14:24:20 +0000
commit9b44ba3ef2c3075706af2bfd744d51e14fd6e52b (patch)
treebffee04a07767c3a5ead9b39b1c001ac4d82d096 /parsers
parent02e475642a813fad3cd7863180a16c272138ccc5 (diff)
downloadtroggle-9b44ba3ef2c3075706af2bfd744d51e14fd6e52b.tar.gz
troggle-9b44ba3ef2c3075706af2bfd744d51e14fd6e52b.tar.bz2
troggle-9b44ba3ef2c3075706af2bfd744d51e14fd6e52b.zip
precompile regexes
Diffstat (limited to 'parsers')
-rw-r--r--parsers/survex.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/parsers/survex.py b/parsers/survex.py
index 9662b54..87c43d0 100644
--- a/parsers/survex.py
+++ b/parsers/survex.py
@@ -130,6 +130,10 @@ class LoadingSurvex():
rx_star = re.compile(r'(?i)\s*\*[\s,]*(\w+)\s*(.*?)\s*(?:;.*)?$')
rx_starref = re.compile(r'(?i)^\s*\*ref[\s.:]*((?:19[6789]\d)|(?:20[0123]\d))\s*#?\s*(X)?\s*(.*?\d+.*?)$')
rx_argsref = re.compile(r'(?i)^[\s.:]*((?:19[6789]\d)|(?:20[0123]\d))\s*#?\s*(X)?\s*(.*?\d+.*?)$')
+
+ rx_ref2 = re.compile(r'(?i)\s*ref[.;]?')
+ rx_ref3 = re.compile(r'(?i)\s*wallet[.;]?')
+
# This interprets the survex "*data normal" command which sets out the order of the fields in the data, e.g.
# *DATA normal from to length gradient bearing ignore ignore ignore ignore
@@ -760,13 +764,18 @@ class LoadingSurvex():
def LoadSurvexComment(self, survexblock, comment):
# ignore all comments except ;ref, ; wallet and ;QM and ;*include (for collated survex file)
+ # rx_ref2 = re.compile(r'(?i)\s*ref[.;]?')
+ # rx_ref3 = re.compile(r'(?i)\s*wallet[.;]?')
+
refline = self.rx_commref.match(comment)
if refline:
- comment = re.sub('(?i)\s*ref[.;]?',"",comment.strip())
+ #comment = re.sub('(?i)\s*ref[.;]?',"",comment.strip())
+ comment = self.rx_ref2.sub("",comment.strip())
self.LoadSurvexRef(survexblock, comment)
walletline = self.rx_wallet.match(comment)
if walletline:
- comment = re.sub('(?i)\s*wallet[.;]?',"",comment.strip())
+ #comment = re.sub('(?i)\s*wallet[.;]?',"",comment.strip())
+ comment = self.rx_ref3.sub("",comment.strip())
self.LoadSurvexRef(survexblock, comment)
implicitline = self.rx_implicit.match(comment)
if implicitline:
@@ -1287,9 +1296,16 @@ def FindAndLoadSurvex(survexblockroot):
# line is held in memory at a time:
with open(collatefilename, "r") as fcollate:
svxlines = fcollate.read().splitlines()
+ #pr2 = cProfile.Profile()
+ #pr2.enable()
#----------------------------------------------------------------
svx_load.LinearLoad(survexblockroot,survexfileroot.path, svxlines)
#----------------------------------------------------------------
+ #pr2.disable()
+ # with open('LinearLoad.prof', 'w') as f:
+ # ps = pstats.Stats(pr2, stream=f)
+ # ps.sort_stats(SortKey.CUMULATIVE)
+ # ps.print_stats()
print("\n - MEM:{:7.2f} MB STOP".format(mem1),file=sys.stderr)
print(" - MEM:{:7.3f} MB USED".format(mem1-mem0),file=sys.stderr)