diff options
| author | Jason Kirtland <jek@discorporate.us> | 2008-08-18 18:57:05 +0000 |
|---|---|---|
| committer | Jason Kirtland <jek@discorporate.us> | 2008-08-18 18:57:05 +0000 |
| commit | ee7366611bb8b40609f7fa4c3eb1b6db17a92db9 (patch) | |
| tree | 61cc07a2b8493b623ec91f5931ee04e188bed18a /lib | |
| parent | 5ba782841e4d10533632ba15822a4a12e22f2c7b (diff) | |
| download | sqlalchemy-ee7366611bb8b40609f7fa4c3eb1b6db17a92db9.tar.gz | |
attributes.get_history now reports some zero-length slots as the empty tuple rather than an empty list. nice speed boost and memory reduction.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/orm/attributes.py | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py index 2c1da5311..d8f32d625 100644 --- a/lib/sqlalchemy/orm/attributes.py +++ b/lib/sqlalchemy/orm/attributes.py @@ -1306,7 +1306,12 @@ class _ClassInstrumentationAdapter(ClassManager): class History(tuple): - # TODO: migrate [] marker for empty slots to () + """A 3-tuple of added, unchanged and deleted values. + + Each tuple member is an iterable sequence. + + """ + __slots__ = () added = property(itemgetter(0)) @@ -1323,9 +1328,9 @@ class History(tuple): if hasattr(attribute, 'get_collection'): current = attribute.get_collection(state, current) if original is NO_VALUE: - return cls(list(current), [], []) + return cls(list(current), (), ()) elif original is NEVER_SET: - return cls([], list(current), []) + return cls((), list(current), ()) else: collection = util.OrderedIdentitySet(current) s = util.OrderedIdentitySet(original) @@ -1337,20 +1342,20 @@ class History(tuple): if original not in [None, NEVER_SET, NO_VALUE]: deleted = [original] else: - deleted = [] - return cls([], [], deleted) + deleted = () + return cls((), (), deleted) elif original is NO_VALUE: - return cls([current], [], []) + return cls([current], (), ()) elif (original is NEVER_SET or attribute.is_equal(current, original) is True): # dont let ClauseElement expressions here trip things up - return cls([], [current], []) + return cls((), [current], ()) else: if original is not None: deleted = [original] else: - deleted = [] - return cls([current], [], deleted) + deleted = () + return cls([current], (), deleted) class PendingCollection(object): |
