From a8c1b2a4637a7770a8769accacec501498bf1ba5 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Wed, 18 Nov 2015 12:12:42 +0100 Subject: [PATCH] Revert copy on write optimization In case of multiple renames, all of the resulting relations will point to the same data, so writing on one and marking its only known copy as writable would be incorrect. For this to work, all the references should be kown to all the other instances. It is probably not worth to implement it. Implemented test for the update --- relational/relation.py | 5 ----- test/update.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 test/update.py diff --git a/relational/relation.py b/relational/relation.py index f69733c..b42169b 100644 --- a/relational/relation.py +++ b/relational/relation.py @@ -54,7 +54,6 @@ class Relation (object): def __init__(self, filename=""): self._readonly = False - self._copy = None self.content = set() if len(filename) == 0: # Empty relation @@ -71,8 +70,6 @@ class Relation (object): self._readonly = True copy._readonly = True - copy._copy = self - self._copy = copy def _make_writable(self, copy_content=True): '''If this relation is marked as readonly, this @@ -83,8 +80,6 @@ class Relation (object): if self._readonly: self._readonly = False - self._copy._readonly = False - self._copy = None if copy_content: self.content = set(self.content) diff --git a/test/update.py b/test/update.py new file mode 100644 index 0000000..b0d0b6a --- /dev/null +++ b/test/update.py @@ -0,0 +1,16 @@ +p1=people +p2=p1.rename({'id':'i'}) +p2=p2.rename({'i':'id'}) +assert p1==p2 +assert p1._readonly +assert p2._readonly +# It is VERY important to not change the original relations +# or other tests might fail randomly, since the relations are +# only loaded once + +p2.update('age==20', {'age':50}) +assert p2._readonly == False +assert p1!=p2 +p3 = p2.selection('age!=50') +p4 = p1.selection('age!=20') +assert p3==p4