From aadca61e0d1eb58f60c44ecaaaad0f68ec7d7e7a Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Sat, 29 Dec 2007 11:51:37 +0000
Subject: [PATCH] Compute loop invariants outside of loop. Iterate over object
 ids instead of over object values. Instead of using find, then spliting
 string, first split and compare with list items. Check that *all* subparts of
 cell id are ints, not just the first one. Remove unneeded value assignment.
 Fix comment. Clarify "try" structure: append is what must happen if no error
 is raised.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18557 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Type/XMLMatrix.py | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/product/ERP5Type/XMLMatrix.py b/product/ERP5Type/XMLMatrix.py
index dd1626c213..a338b04e22 100644
--- a/product/ERP5Type/XMLMatrix.py
+++ b/product/ERP5Type/XMLMatrix.py
@@ -212,20 +212,22 @@ class XMLMatrix(Folder):
 
       # List all valid cell ids for current base_id.
       object_id_list = []
-      for obj in self.objectValues():
-        object_id = obj.getId()
-        if object_id.find(base_id) == 0:
-          # Check that all '_'-separated fields are of int type.
-          if (object_id) > len(base_id):
-            try:
-              int(object_id[len(base_id)+1:].split('_')[0])
-              test = self._getOb(object_id) # If the object was created
-                                            # during this transaction,
-                                            # then we do not need to
-                                            # work on it
-              object_id_list.append(object_id)
-            except (ValueError, KeyError):
-              pass
+      base_id_len = len(base_id)
+      for object_id in self.objectIds():
+        object_id_list = object_id.split('_')
+        if len(object_id_list) > 1 and object_id_list.pop(0) == base_id:
+          try:
+            # Check that all '_'-separated fields are of int type (once
+            # base_id is poped).
+            [int(x) for x in object_id_list]
+            self._getOb(object_id) # If the object was created
+                                   # during this transaction,
+                                   # then we do not need to
+                                   # work on it
+          except (ValueError, KeyError):
+            pass
+          else:
+            object_id_list.append(object_id)
 
       # Prepend 'temp_' to all cells, to avoid id conflicts while renaming.
       for object_id in object_id_list:
-- 
2.30.9