changeset 51:f5cfdd80cfe7 draft

state: Make ParseState.hold() about 20% faster
author Lewin Bormann <lbo@spheniscida.de>
date Thu, 23 May 2019 22:56:33 +0200
parents 4a86c41e42f1
children bc662ab63361
files pcombinators/combinators.py pcombinators/state.py
diffstat 2 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pcombinators/combinators.py	Thu May 23 22:37:55 2019 +0200
+++ b/pcombinators/combinators.py	Thu May 23 22:56:33 2019 +0200
@@ -70,7 +70,7 @@
             st.reset(hold)
             return None, st
         try:
-            r2 =  self._transform(r)
+            r2 = self._transform(r)
             st2.release(hold)
             return r2, st2
         except Exception as e:
--- a/pcombinators/state.py	Thu May 23 22:37:55 2019 +0200
+++ b/pcombinators/state.py	Thu May 23 22:56:33 2019 +0200
@@ -33,16 +33,16 @@
     # Holds are a simple garbage collection mechanism by which parsers should
     # indicate which parts of state they may still backtrack to.
     class ParserHold:
-        def __init__(self, i):
-            self.total_index = i
-        total_index = 0
+        pass
 
     def _maybe_collect(self):
         pass
 
     def hold(self):
         self._holds.append(self.index())
-        return self.ParserHold(self.index())
+        hold = _State.ParserHold()
+        hold.total_index = self.index()
+        return hold
 
     def release(self, hold):
         """Release a hold. Generally called when a parser was successful."""