← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/bool-opt into lp:zorba

 

Matthias Brantner has proposed merging lp:~zorba-coders/zorba/bool-opt into lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bool-opt/+merge/84515

optimization: only have exactly two instances of boolean items in the simple store
-- 
https://code.launchpad.net/~zorba-coders/zorba/bool-opt/+merge/84515
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/store/naive/simple_item_factory.cpp'
--- src/store/naive/simple_item_factory.cpp	2011-10-15 10:41:19 +0000
+++ src/store/naive/simple_item_factory.cpp	2011-12-05 18:26:25 +0000
@@ -43,15 +43,19 @@
 BasicItemFactory::BasicItemFactory(UriPool* uriPool, QNamePool* qnPool)
   :
   theUriPool(uriPool),
-  theQNamePool(qnPool)
+  theQNamePool(qnPool),
+  theTrueItem(NULL),
+  theFalseItem(NULL)
 {
 }
 
 
 BasicItemFactory::~BasicItemFactory()
 {
+  theFalseItem = NULL;
+  theTrueItem  = NULL;
   theQNamePool = NULL;
-  theUriPool = NULL;
+  theUriPool   = NULL;
 }
 
 
@@ -421,7 +425,22 @@
 
 bool BasicItemFactory::createBoolean(store::Item_t& result, xs_boolean value)
 {
-  result = new BooleanItem(value);
+  if (value)
+  {
+    if (!theTrueItem)
+    {
+      theTrueItem = new BooleanItem(true);
+    }
+    result = theTrueItem;
+  }
+  else
+  {
+    if (!theFalseItem)
+    {
+      theFalseItem = new BooleanItem(false);
+    }
+    result = theFalseItem;
+  }
   return true;
 }
 

=== modified file 'src/store/naive/simple_item_factory.h'
--- src/store/naive/simple_item_factory.h	2011-10-15 10:41:19 +0000
+++ src/store/naive/simple_item_factory.h	2011-12-05 18:26:25 +0000
@@ -50,6 +50,13 @@
   UriPool    * theUriPool;
   QNamePool  * theQNamePool;
 
+  // boolean items
+  // we don't need to create more than two, hence
+  // they are cached here. createBoolean always
+  // returns one of them
+  store::Item_t theTrueItem;
+  store::Item_t theFalseItem;
+
 public:
   BasicItemFactory(UriPool* uriPool, QNamePool* qnPool);
 


Follow ups