From 03380380efb5d5c0b2a3acfaa64b486ee2cb6e64 Mon Sep 17 00:00:00 2001 From: Clay Gerrard Date: Thu, 23 Apr 2015 19:39:16 -0700 Subject: [PATCH] Simplify ring.builder.RingBuilder.__deepcopy__ Only container classes (lists, sets, dicts, graphs, collections, etc) need to track objects they deepcopy in the memo dict - particularly when they may contain other containers! As they recreate a new container with the same items as themselves, they'll reference the memo for each item they contain before making a deepcopy of it, and place a reference to the copied item into memo after they do. Trying to help out some other container class in this endeavor by attempting to add ourselves to the memo dict in some useful manor on their behalf however; is not helpful. All we need to do to make sure we're being a good __deepcopy__ implementation is make sure we pass on memo to our calls of deepcopy so that other container classes can avoid making additional deepcopy's of our containers if they already have a memorized copy (which would be odd since unique instances of RingBuilders aren't expected to share state, but hey - python doesn't have private attributes so you never know!) Change-Id: Ifac444dffbf79d650b2d858f6282e05d8ea741a0 --- swift/common/ring/builder.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/swift/common/ring/builder.py b/swift/common/ring/builder.py index c0a37f8a54..e51ef71c9f 100644 --- a/swift/common/ring/builder.py +++ b/swift/common/ring/builder.py @@ -181,9 +181,7 @@ class RingBuilder(object): dev.setdefault("region", 1) def __deepcopy__(self, memo): - the_copy = type(self).from_dict(deepcopy(self.to_dict(), memo)) - memo[id(self)] = the_copy - return the_copy + return type(self).from_dict(deepcopy(self.to_dict(), memo)) def to_dict(self): """