Rev 5375: Do some memory shrinking for multiparent. in http://bazaar.launchpad.net/~jameinel/bzr/2.3-send-mem-614576

John Arbash Meinel john at arbash-meinel.com
Tue Aug 10 18:01:46 BST 2010


At http://bazaar.launchpad.net/~jameinel/bzr/2.3-send-mem-614576

------------------------------------------------------------
revno: 5375
revision-id: john at arbash-meinel.com-20100810170137-30ug1zkmjah15saf
parent: pqm at pqm.ubuntu.com-20100807214836-umokeeg6d1dytzvm
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.3-send-mem-614576
timestamp: Tue 2010-08-10 12:01:37 -0500
message:
  Do some memory shrinking for multiparent.
  
  The NewText and ParentText objects were not using __slots__.
  And for big merge directives (or any patches) there could be
  lots of these objects in memory.
-------------- next part --------------
=== modified file 'bzrlib/multiparent.py'
--- a/bzrlib/multiparent.py	2009-06-10 03:56:49 +0000
+++ b/bzrlib/multiparent.py	2010-08-10 17:01:37 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2007 Canonical Ltd
+# Copyright (C) 2007-2010 Canonical Ltd
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -76,6 +76,8 @@
 class MultiParent(object):
     """A multi-parent diff"""
 
+    __slots__ = ('hunks')
+
     def __init__(self, hunks=None):
         if hunks is not None:
             self.hunks = hunks
@@ -258,6 +260,8 @@
 class NewText(object):
     """The contents of text that is introduced by this text"""
 
+    __slots__ = ['lines']
+
     def __init__(self, lines):
         self.lines = lines
 
@@ -279,24 +283,30 @@
 class ParentText(object):
     """A reference to text present in a parent text"""
 
+    __slots__ = ['parent', 'parent_pos', 'child_pos', 'num_lines']
+
     def __init__(self, parent, parent_pos, child_pos, num_lines):
         self.parent = parent
         self.parent_pos = parent_pos
         self.child_pos = child_pos
         self.num_lines = num_lines
 
+    def _as_dict(self):
+        return dict(parent=self.parent, parent_pos=self.parent_pos,
+                    child_pos=self.child_pos, num_lines=self.num_lines)
+
     def __repr__(self):
-        return 'ParentText(%(parent)r, %(parent_pos)r, %(child_pos)r,'\
-            ' %(num_lines)r)' % self.__dict__
+        return ('ParentText(%(parent)r, %(parent_pos)r, %(child_pos)r,'
+                ' %(num_lines)r)' % self._as_dict())
 
     def __eq__(self, other):
         if self.__class__ is not other.__class__:
             return False
-        return (self.__dict__ == other.__dict__)
+        return self._as_dict() == other._as_dict()
 
     def to_patch(self):
-        yield 'c %(parent)d %(parent_pos)d %(child_pos)d %(num_lines)d\n'\
-            % self.__dict__
+        yield ('c %(parent)d %(parent_pos)d %(child_pos)d %(num_lines)d\n'
+               % self._as_dict())
 
 
 class BaseVersionedFile(object):



More information about the bazaar-commits mailing list