Commits

Alex Gaynor  committed aa9eef5

remove unnecsary use of weakrefs from our sqlite3. This is worth about 25% on the sqlite benchmark.

  • Participants
  • Parent commits 68fbc67

Comments (0)

Files changed (1)

File lib_pypy/_sqlite3.py

 
         if self.statement.kind == DQL and ret == SQLITE_ROW:
             self.statement._build_row_cast_map()
-            self.statement._readahead()
+            self.statement._readahead(self)
         else:
             self.statement.item = None
             self.statement.exhausted = True
             sql = sql.encode("utf-8")
         self._check_closed()
         self.statement = self.connection.statement_cache.get(sql, self, self.row_factory)
-        
+
         if self.statement.kind == DML:
             self.connection._begin()
         else:
         return self
 
     def __iter__(self):
-        return self.statement
+        return iter(self.fetchone, None)
 
     def _check_reset(self):
         if self.reset:
             return None
 
         try:
-            return self.statement.next()
+            return self.statement.next(self)
         except StopIteration:
             return None
 
         if size is None:
             size = self.arraysize
         lst = []
-        for row in self.statement:
+        for row in self:
             lst.append(row)
             if len(lst) == size:
                 break
         self._check_reset()
         if self.statement is None:
             return []
-        return list(self.statement)
+        return list(self)
 
     def _getdescription(self):
         if self._description is None:
         self._build_row_cast_map()
 
     def set_cursor_and_factory(self, cur, row_factory):
-        self.cur = weakref.ref(cur)
         self.row_factory = row_factory
 
     def _build_row_cast_map(self):
                     raise ProgrammingError("missing parameter '%s'" %param)
                 self.set_param(idx, param)
 
-    def __iter__(self):
-        return self
-
-    def next(self):
+    def next(self, cursor):
         self.con._check_closed()
         self.con._check_thread()
         if self.exhausted:
             sqlite.sqlite3_reset(self.statement)
             raise exc
 
-        self._readahead()
+        self._readahead(cursor)
         return item
 
-    def _readahead(self):
+    def _readahead(self, cursor):
         self.column_count = sqlite.sqlite3_column_count(self.statement)
         row = []
         for i in xrange(self.column_count):
 
         row = tuple(row)
         if self.row_factory is not None:
-            row = self.row_factory(self.cur(), row)
+            row = self.row_factory(cursor, row)
         self.item = row
 
     def reset(self):