← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/markos-scratch into lp:zorba

 

Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch into lp:zorba.

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/91867

optimization for the Item::add/removeReference methods
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/91867
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/store/api/item.h'
--- src/store/api/item.h	2012-01-26 19:56:14 +0000
+++ src/store/api/item.h	2012-02-07 16:00:39 +0000
@@ -51,7 +51,7 @@
  */
 class ZORBA_DLL_PUBLIC Item
 {
-protected:
+public:
   enum ItemKind
   {
     NODE       = 0x10,
@@ -62,6 +62,7 @@
     ERROR_     = 0x201
   };
 
+protected:
   typedef union 
   {
     long    * treeRCPtr;
@@ -104,6 +105,11 @@
   /* -------------------   General Methods for Items ------------------------- */
 
   /**
+   * @return the kind of the item
+   */
+  ItemKind getKind() const;
+
+  /**
    *  @return  "true" if the item is a node
    */
   bool 

=== modified file 'src/store/naive/item.cpp'
--- src/store/naive/item.cpp	2012-01-26 19:56:14 +0000
+++ src/store/naive/item.cpp	2012-02-07 16:00:39 +0000
@@ -52,36 +52,48 @@
 
 #else
 
-  if (isNode())
+  switch (getKind())
+  {
+  case NODE:
   {
     SYNC_CODE(static_cast<const simplestore::XmlNode*>(this)->getRCLock()->acquire());
     ++(*theUnion.treeRCPtr);
     ++theRefCount;
     SYNC_CODE(static_cast<const simplestore::XmlNode*>(this)->getRCLock()->release());
+    return;
   }
-  else if (isAtomic() || isError())
+  case ATOMIC:
+  case ERROR_:
   {
     SYNC_CODE(static_cast<const simplestore::AtomicItem*>(this)->getRCLock()->acquire());
     ++theRefCount;
     SYNC_CODE(static_cast<const simplestore::AtomicItem*>(this)->getRCLock()->release());
+    return;
   }
-  else if (isList())
+  case LIST:
   {
     SYNC_CODE(static_cast<const simplestore::ItemVector*>(this)->getRCLock()->acquire());
     ++theRefCount;
     SYNC_CODE(static_cast<const simplestore::ItemVector*>(this)->getRCLock()->release());
+    return;
   }
-  else if (isFunction())
+  case FUNCTION:
   {
     SYNC_CODE(static_cast<const FunctionItem*>(this)->getRCLock()->acquire());
     ++theRefCount;
     SYNC_CODE(static_cast<const FunctionItem*>(this)->getRCLock()->release());
+    return;
   }
-  else
+  case PUL:
   {
     ++theRefCount;
-  }
-
+    return;
+  }
+  default:
+  {
+    ZORBA_ASSERT(false);
+  }  
+  }
 #endif
 }
 
@@ -106,7 +118,9 @@
 
 #else
 
-  if (isNode())
+  switch (getKind())
+  {
+  case NODE:
   {
     SYNC_CODE(static_cast<const simplestore::XmlNode*>(this)->getRCLock()->acquire());
 
@@ -119,8 +133,10 @@
     }
 
     SYNC_CODE(static_cast<const simplestore::XmlNode*>(this)->getRCLock()->release());
+    return;
   }
-  else if (isAtomic() || isError())
+  case ATOMIC:
+  case ERROR_:
   {
     SYNC_CODE(static_cast<const simplestore::AtomicItem*>(this)->getRCLock()->acquire());
 
@@ -132,8 +148,9 @@
     }
 
     SYNC_CODE(static_cast<const simplestore::AtomicItem*>(this)->getRCLock()->release());
+    return;
   }
-  else if (isList())
+  case LIST:
   {
     SYNC_CODE(static_cast<const simplestore::ItemVector*>(this)->getRCLock()->acquire());
 
@@ -145,8 +162,9 @@
     }
 
     SYNC_CODE(static_cast<const simplestore::ItemVector*>(this)->getRCLock()->release());
+    return;
   }
-  else if (isFunction())
+  case FUNCTION:
   {
     SYNC_CODE(static_cast<const FunctionItem*>(this)->getRCLock()->acquire());
 
@@ -158,17 +176,37 @@
     }
 
     SYNC_CODE(static_cast<const FunctionItem*>(this)->getRCLock()->release());
+    return;
   }
-  else // PUL
+  case  PUL:
   {
     if (--theRefCount == 0)
       free();
+
+    return;
+  }
+  default:
+  {
+    ZORBA_ASSERT(false);
+  }
   }
 
 #endif
 }
 
 
+Item::ItemKind Item::getKind() const
+{
+  //if (theUnion.treeRCPtr == 0)
+  //  return UNKNOWN;
+
+  if ((reinterpret_cast<uint64_t>(theUnion.treeRCPtr) & 0x1) == 0)
+    return NODE;
+
+  return static_cast<ItemKind>(theUnion.itemKind);
+}
+
+
 bool Item::isNode() const
 {
   return ((reinterpret_cast<uint64_t>(theUnion.treeRCPtr) & 0x1) == 0 &&
@@ -178,31 +216,31 @@
 
 bool Item::isAtomic() const
 {
-  return ((theUnion.itemKind & ATOMIC) == ATOMIC); 
+  return (theUnion.itemKind == ATOMIC); 
 }
 
 
 bool Item::isList() const
 {
-  return ((theUnion.itemKind & LIST) == LIST); 
+  return (theUnion.itemKind == LIST); 
 }
 
 
 bool Item::isPul() const
 {
-  return ((theUnion.itemKind & PUL) == PUL);
+  return (theUnion.itemKind == PUL);
 }
 
 
 bool Item::isError() const
 {
-  return ((theUnion.itemKind & ERROR_) == ERROR_);
+  return (theUnion.itemKind == ERROR_);
 }
 
 
 bool Item::isFunction() const
 {
-  return ((theUnion.itemKind & FUNCTION) == FUNCTION);
+  return (theUnion.itemKind == FUNCTION);
 }
 
 

=== modified file 'src/store/naive/item_vector.cpp'
--- src/store/naive/item_vector.cpp	2011-06-14 17:26:33 +0000
+++ src/store/naive/item_vector.cpp	2012-02-07 16:00:39 +0000
@@ -22,7 +22,9 @@
 
 namespace zorba { namespace simplestore {
 
-ItemVector::ItemVector(std::vector<store::Item_t>& items)
+ItemVector::ItemVector(std::vector<store::Item_t>& items) 
+  :
+  store::Item(LIST)
 {
   size_t numItems = items.size();
 


Follow ups