From bd3b9cfd0e190aac81da1180bc09de08d04cfd3e Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Wed, 17 Nov 2010 13:05:13 +0000
Subject: [PATCH] Micro optimisation: disable/enable function rather than
 testing upon call.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2460 71dcc9de-d417-0410-9af5-da40c76e7ee4
---
 neo/storage/database/btree.py | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/neo/storage/database/btree.py b/neo/storage/database/btree.py
index 80b130f6..7cbfc191 100644
--- a/neo/storage/database/btree.py
+++ b/neo/storage/database/btree.py
@@ -41,12 +41,23 @@ def OOBTree():
         result = TREE_POOL.pop()
     except IndexError:
         result = _OOBTree()
+    # Next btree we prune will have room, restore prune method
+    global prune
+    prune = _prune
     return result
 
-def prune(tree):
-    if len(TREE_POOL) < MAX_TREE_POOL_SIZE:
-        tree.clear()
-        TREE_POOL.append(tree)
+def _prune(tree):
+    tree.clear()
+    TREE_POOL.append(tree)
+    if len(TREE_POOL) >= MAX_TREE_POOL_SIZE:
+        # Already at/above max pool size, disable ourselve.
+        global prune
+        prune = _noPrune
+
+def _noPrune(_):
+    pass
+
+prune = _prune
 
 class CreationUndone(Exception):
     pass
-- 
2.30.9