From a4b22193c2c3f189a690821bbc6c32b5f01f73e3 Mon Sep 17 00:00:00 2001 From: Gerald Britton Date: Wed, 13 Jan 2010 15:46:12 +0000 Subject: [PATCH] Use defaultdict instead of dict to simplify code and improve performance svn: r14060 --- src/gen/db/txn.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/gen/db/txn.py b/src/gen/db/txn.py index 862bb7c80..3ec6f2a58 100644 --- a/src/gen/db/txn.py +++ b/src/gen/db/txn.py @@ -34,6 +34,7 @@ from __future__ import with_statement import cPickle as pickle from bsddb import dbshelve, db import logging +from collections import defaultdict #------------------------------------------------------------------------- # @@ -51,7 +52,7 @@ _LOG = logging.getLogger(DBLOGNAME) # Gramps transaction class # #------------------------------------------------------------------------- -class DbTxn(dict): +class DbTxn(defaultdict): """ Define a group of database commits that define a single logical operation. This class should not be used directly, but subclassed to reference a real @@ -108,7 +109,7 @@ class DbTxn(dict): data = pickled representation of the object """ - super(DbTxn, self).__init__({}) + defaultdict.__init__(self, list, {}) self.msg = msg self.commitdb = commitdb @@ -158,10 +159,8 @@ class DbTxn(dict): self.last = len(self.commitdb) -1 if self.first is None: self.first = self.last - if (obj_type, trans_type) in self: - self[(obj_type, trans_type)] += [(handle, new_data)] - else: - self[(obj_type, trans_type)] = [(handle, new_data)] + self[(obj_type, trans_type)] += [(handle, new_data)] + return def get_recnos(self, reverse=False): """