summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@openbossa.org>2011-01-12 19:30:23 -0300
committerRenato Araujo Oliveira Filho <renato.filho@openbossa.org>2011-01-13 10:37:13 -0300
commitb719c4e8b9238ea8c4d1e022cf597e8cb628f5d7 (patch)
treea07ab1bd6951508d3c289b8e1d27852e40649a83
parent297151081ffae13c8dbb66ffde61f2c15eaae2a3 (diff)
downloadshiboken-b719c4e8b9238ea8c4d1e022cf597e8cb628f5d7.tar.gz
shiboken-b719c4e8b9238ea8c4d1e022cf597e8cb628f5d7.tar.xz
shiboken-b719c4e8b9238ea8c4d1e022cf597e8cb628f5d7.zip
Optimized setParent function.
Replaced use of find in the children list for check on the current child if his has a parent and if the parent is the same. Fixes bug #556 Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Hugo Parente <hugo.lima@openbossa.org>
-rw-r--r--libshiboken/basewrapper.cpp4
-rw-r--r--tests/samplebinding/ownership_reparenting_test.py10
2 files changed, 12 insertions, 2 deletions
diff --git a/libshiboken/basewrapper.cpp b/libshiboken/basewrapper.cpp
index 1f0327b7..71892e42 100644
--- a/libshiboken/basewrapper.cpp
+++ b/libshiboken/basewrapper.cpp
@@ -910,9 +910,9 @@ void setParent(PyObject* parent, PyObject* child)
if (!parentIsNull) {
if (!parent_->d->parentInfo)
parent_->d->parentInfo = new ParentInfo;
+
// do not re-add a child
- ChildrenList& children = parent_->d->parentInfo->children;
- if (std::find(children.begin(), children.end(), child_) != children.end())
+ if (child_->d->parentInfo && (child_->d->parentInfo->parent == parent_))
return;
}
diff --git a/tests/samplebinding/ownership_reparenting_test.py b/tests/samplebinding/ownership_reparenting_test.py
index 3e68287b..395ce393 100644
--- a/tests/samplebinding/ownership_reparenting_test.py
+++ b/tests/samplebinding/ownership_reparenting_test.py
@@ -27,6 +27,7 @@
'''Tests for object reparenting.'''
import unittest
+import sys
from sample import ObjectType
@@ -52,6 +53,15 @@ class ReparentingTest(unittest.TestCase):
for child in new_parent.children():
self.assert_(child in object_list)
+ def testReparentWithTheSameParent(self):
+ '''Set the same parent twice to check if the ref continue the same'''
+ obj = ObjectType()
+ parent = ObjectType()
+ self.assertEqual(sys.getrefcount(obj), 2)
+ obj.setParent(parent)
+ self.assertEqual(sys.getrefcount(obj), 3)
+ obj.setParent(parent)
+ self.assertEqual(sys.getrefcount(obj), 3)
def testReparentedExtObjectType(self):
'''Reparent children from one extended parent to another.'''