2 new revisions:

Revision: a4a97f60294a
Branch:   default
Author:   Pekka Klärck
Date:     Wed Aug 28 12:46:38 2013 UTC
Log: model: avoid creating (empty) lists when not necessary to save a littl...
http://code.google.com/p/robotframework/source/detail?r=a4a97f60294a

Revision: 479810dd8c53
Branch:   default
Author:   Pekka Klärck
Date:     Wed Aug 28 12:51:17 2013 UTC
Log: ItemList: use tuples, not lists, as the backend storage, to save memor...
http://code.google.com/p/robotframework/source/detail?r=479810dd8c53

==============================================================================
Revision: a4a97f60294a
Branch:   default
Author:   Pekka Klärck
Date:     Wed Aug 28 12:46:38 2013 UTC
Log: model: avoid creating (empty) lists when not necessary to save a little memory
http://code.google.com/p/robotframework/source/detail?r=a4a97f60294a

Modified:
 /src/robot/model/itemlist.py
 /src/robot/model/keyword.py
 /src/robot/model/metadata.py
 /src/robot/model/testcase.py
 /src/robot/model/testsuite.py

=======================================
--- /src/robot/model/itemlist.py        Tue Aug 27 19:24:22 2013 UTC
+++ /src/robot/model/itemlist.py        Wed Aug 28 12:46:38 2013 UTC
@@ -33,7 +33,7 @@

     def _check_type_and_set_attrs(self, item):
         if not isinstance(item, self._item_class):
-            raise TypeError("Only '%s' objects accepted, got '%s'"
+            raise TypeError("Only '%s' objects accepted, got '%s'."
% (self._item_class.__name__, type(item).__name__))
         if self._common_attrs:
             for attr in self._common_attrs:
=======================================
--- /src/robot/model/keyword.py Tue Aug 27 13:18:31 2013 UTC
+++ /src/robot/model/keyword.py Wed Aug 28 12:46:38 2013 UTC
@@ -46,9 +46,9 @@
         self.timeout = timeout
         #: Keyword messages, a list of
         #: :class:`~robot.model.message.Messages` instances.
-        self.messages = []
+        self.messages = None
         #: Child keyword results, a list of class:`~.Keyword`. instances
-        self.keywords = []
+        self.keywords = None

     @setter
     def keywords(self, keywords):
=======================================
--- /src/robot/model/metadata.py        Thu Jun  6 14:00:44 2013 UTC
+++ /src/robot/model/metadata.py        Wed Aug 28 12:46:38 2013 UTC
@@ -18,7 +18,7 @@
 class Metadata(NormalizedDict):

     def __init__(self, initial=None):
-        NormalizedDict.__init__(self, initial, ignore=['_'])
+        NormalizedDict.__init__(self, initial, ignore='_')

     def __unicode__(self):
         return u'{%s}' % ', '.join('%s: %s' % (k, self[k]) for k in self)
=======================================
--- /src/robot/model/testcase.py        Tue Jun 11 11:28:49 2013 UTC
+++ /src/robot/model/testcase.py        Wed Aug 28 12:46:38 2013 UTC
@@ -21,8 +21,7 @@


 class TestCase(ModelObject):
-    """Base model for single test case.
-    """
+    """Base model for single test case."""
     __slots__ = ['parent', 'name', 'doc', 'timeout']
     keyword_class = Keyword

@@ -39,7 +38,7 @@
         self.timeout = timeout
         #: Keyword results, a list of :class:`~.keyword.Keyword`
#: instances and contains also possible setup and teardown keywords.
-        self.keywords = []
+        self.keywords = None

     @setter
     def tags(self, tags):
=======================================
--- /src/robot/model/testsuite.py       Tue Jun 11 11:28:49 2013 UTC
+++ /src/robot/model/testsuite.py       Wed Aug 28 12:46:38 2013 UTC
@@ -43,12 +43,12 @@
         #: Path to the source file or directory.
         self.source = source
         #: A list of child :class:`~.testsuite.TestSuite` instances.
-        self.suites = []
+        self.suites = None
         #: A list of :class:`~.testcase.TestCase` instances.
-        self.tests = []
+        self.tests = None
         #: A list containing setup and teardown as
         #: :class:`~keyword.Keyword` instances.
-        self.keywords = []
+        self.keywords = None
         self._my_visitors = []

     @property

==============================================================================
Revision: 479810dd8c53
Branch:   default
Author:   Pekka Klärck
Date:     Wed Aug 28 12:51:17 2013 UTC
Log: ItemList: use tuples, not lists, as the backend storage, to save memory.

Tuples in general take a little less memory than lists because the latter reserve memory for possible elements to be added. The difference is biggest with empty tuples vs empty lists, because the former are implemented as singletons in Python.

A drawback of this change is that `list.append(item)` is a bit faster than `tuple += (item,)`. With short sequences the difference is insignificant, though, and most of the ItemLists are rather short.
http://code.google.com/p/robotframework/source/detail?r=479810dd8c53

Modified:
 /src/robot/model/itemlist.py

=======================================
--- /src/robot/model/itemlist.py        Wed Aug 28 12:46:38 2013 UTC
+++ /src/robot/model/itemlist.py        Wed Aug 28 12:51:17 2013 UTC
@@ -19,7 +19,7 @@
     def __init__(self, item_class, common_attrs=None, items=None):
         self._item_class = item_class
         self._common_attrs = common_attrs
-        self._items = []
+        self._items = ()
         if items:
             self.extend(items)

@@ -28,7 +28,7 @@

     def append(self, item):
         self._check_type_and_set_attrs(item)
-        self._items.append(item)
+        self._items += (item,)
         return item

     def _check_type_and_set_attrs(self, item):
@@ -42,13 +42,17 @@
     def extend(self, items):
         for item in items:
             self._check_type_and_set_attrs(item)
-        self._items.extend(items)
+        self._items += tuple(items)

-    def index(self, item):
-        return self._items.index(item)
+    if hasattr(tuple, 'index'):  # tuples got index method in Python 2.6
+        def index(self, item):
+            return self._items.index(item)
+    else:
+        def index(self, item):
+            return list(self._items).index(item)

     def clear(self):
-        self._items = []
+        self._items = ()

     def visit(self, visitor):
         for item in self:

--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to