[Bf-extensions-cvs] [8753d57] master: Fix for costly pop() function calls on lists.

Lukas Tönne noreply at git.blender.org
Sat Dec 13 11:06:55 CET 2014

Commit: 8753d57c7a9a57061dce8d139476836ba0b647ce
Author: Lukas Tönne
Date:   Sat Dec 13 00:51:57 2014 +0100
Branches: master

Fix for costly pop() function calls on lists.

These are called a lot when the number of active cells (overall sampling
area) grows. Popping an element in the middle of a list is much more
expensive than popping from the end, but since we don't actually care
about ordering, we can simply swap the element for the one at the end.


M	object_physics_meadow/hierarchical_dart_throw.py


diff --git a/object_physics_meadow/hierarchical_dart_throw.py b/object_physics_meadow/hierarchical_dart_throw.py
index 2ced12f..37347a5 100644
--- a/object_physics_meadow/hierarchical_dart_throw.py
+++ b/object_physics_meadow/hierarchical_dart_throw.py
@@ -57,7 +57,9 @@ class GridLevel():
         return cell
     def deactivate(self, index):
-        return self.cells.pop(index)
+        c = self.cells[index]
+        self.cells[index] = self.cells.pop()
+        return c
     def cell_corners(self, cell):
         x0 = float(cell.i)

More information about the Bf-extensions-cvs mailing list