For immutable config attributes, use shallow copy for speed and memory
authorZac Medico <zmedico@gentoo.org>
Tue, 2 Mar 2010 18:27:10 +0000 (18:27 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 2 Mar 2010 18:27:10 +0000 (18:27 -0000)
conservation. (trunk r15283)

svn path=/main/branches/2.1.7/; revision=15522

pym/portage/__init__.py

index 381413bec76c2ac59adc061aa4e995a303a5c511..144378890f65640bd55b8273cea605fc7e851604 100644 (file)
@@ -1581,8 +1581,13 @@ class config(object):
                self._local_repo_conf_path = None
 
                if clone:
-                       self.incrementals = copy.deepcopy(clone.incrementals)
-                       self.profile_path = copy.deepcopy(clone.profile_path)
+                       # For immutable attributes, use shallow copy for
+                       # speed and memory conservation.
+                       self.incrementals = clone.incrementals
+                       self.profile_path = clone.profile_path
+                       self.profiles = clone.profiles
+                       self.packages = clone.packages
+
                        self.user_profile_dir = copy.deepcopy(clone.user_profile_dir)
                        self.local_config = copy.deepcopy(clone.local_config)
                        self._local_repo_configs = \
@@ -1594,10 +1599,7 @@ class config(object):
                        self.modules         = copy.deepcopy(clone.modules)
 
                        self.depcachedir = copy.deepcopy(clone.depcachedir)
-
-                       self.packages = copy.deepcopy(clone.packages)
                        self.virtuals = copy.deepcopy(clone.virtuals)
-
                        self.dirVirtuals = copy.deepcopy(clone.dirVirtuals)
                        self.treeVirtuals = copy.deepcopy(clone.treeVirtuals)
                        self.userVirtuals = copy.deepcopy(clone.userVirtuals)
@@ -1631,7 +1633,6 @@ class config(object):
                        self.lookuplist = self.configlist[:]
                        self.lookuplist.reverse()
                        self._use_expand_dict = copy.deepcopy(clone._use_expand_dict)
-                       self.profiles = copy.deepcopy(clone.profiles)
                        self.backupenv  = self.configdict["backupenv"]
                        self.pusedict   = copy.deepcopy(clone.pusedict)
                        self.categories = copy.deepcopy(clone.categories)
@@ -1675,12 +1676,14 @@ class config(object):
                                else:
                                        self.profile_path = None
                        else:
-                               self.profile_path = config_profile_path[:]
+                               self.profile_path = config_profile_path
 
                        if config_incrementals is None:
-                               self.incrementals = copy.deepcopy(portage.const.INCREMENTALS)
+                               self.incrementals = portage.const.INCREMENTALS
                        else:
-                               self.incrementals = copy.deepcopy(config_incrementals)
+                               self.incrementals = config_incrementals
+                       if not isinstance(self.incrementals, tuple):
+                               self.incrementals = tuple(self.incrementals)
 
                        self.module_priority    = ["user","default"]
                        self.modules            = {}
@@ -1760,8 +1763,9 @@ class config(object):
                                        self.profiles.append(custom_prof)
                                del custom_prof
 
+                       self.profiles = tuple(self.profiles)
                        self.packages_list = [grabfile_package(os.path.join(x, "packages")) for x in self.profiles]
-                       self.packages      = stack_lists(self.packages_list, incremental=1)
+                       self.packages      = tuple(stack_lists(self.packages_list, incremental=1))
                        del self.packages_list
                        #self.packages = grab_stacked("packages", self.profiles, grabfile, incremental_lines=1)