Author: Armin Rigo <[email protected]>
Branch:
Changeset: r89555:15abf75346b2
Date: 2017-01-14 10:07 +0100
http://bitbucket.org/pypy/pypy/changeset/15abf75346b2/
Log: A WeakSet is not necessary: just copy the list of weakrefs. We don't
need extra logic to remember statements in previous commits, because
they are still in self.__statements now unless their weakref died.
diff --git a/lib_pypy/_sqlite3.py b/lib_pypy/_sqlite3.py
--- a/lib_pypy/_sqlite3.py
+++ b/lib_pypy/_sqlite3.py
@@ -220,7 +220,7 @@
self.__statements_counter = 0
self.__rawstatements = set()
self._statement_cache = _StatementCache(self, cached_statements)
- self.__statements_already_committed = weakref.WeakSet()
+ self.__statements_already_committed = []
self.__func_cache = {}
self.__aggregates = {}
@@ -365,10 +365,12 @@
cursor._reset = True
def _reset_already_committed_statements(self):
- lst = list(self.__statements_already_committed)
- self.__statements_already_committed.clear()
- for statement in lst:
- statement._reset()
+ lst = self.__statements_already_committed
+ self.__statements_already_committed = []
+ for weakref in lst:
+ statement = weakref()
+ if statement is not None:
+ statement._reset()
@_check_thread_wrap
@_check_closed_wrap
@@ -432,14 +434,11 @@
# the way and cause the "drop table" to fail. On CPython the
# problem is much less important because typically all the old
# statements are freed already by reference counting. So here,
- # we add all the still-alive statements to a WeakSet which is
- # usually ignored, except if we get SQLITE_LOCKED
+ # we copy all the still-alive statements to another list which
+ # is usually ignored, except if we get SQLITE_LOCKED
# afterwards---at which point we reset all statements in this
- # WeakSet.
- for weakref in self.__statements:
- statement = weakref()
- if statement is not None:
- self.__statements_already_committed.add(statement)
+ # list.
+ self.__statements_already_committed = self.__statements[:]
statement_star = _ffi.new('sqlite3_stmt **')
ret = _lib.sqlite3_prepare_v2(self._db, b"COMMIT", -1,
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit