Ghislain Fourny has proposed merging lp:~zorba-coders/zorba/unregister-delete-or-destroy into lp:zorba.
Requested reviews: Matthias Brantner (matthias-brantner) For more details, see: https://code.launchpad.net/~zorba-coders/zorba/unregister-delete-or-destroy/+merge/100814 Differentiating between two reasons why references are unregistered. -- https://code.launchpad.net/~zorba-coders/zorba/unregister-delete-or-destroy/+merge/100814 Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/store/naive/node_items.cpp' --- src/store/naive/node_items.cpp 2012-03-28 23:58:23 +0000 +++ src/store/naive/node_items.cpp 2012-04-04 15:35:31 +0000 @@ -142,7 +142,7 @@ /******************************************************************************* ********************************************************************************/ -void XmlTree::free() +void XmlTree::destroy() throw() { // std::cout << "Deleting Xml Tree: " << this << std::endl; @@ -169,6 +169,16 @@ } +/******************************************************************************* + +********************************************************************************/ +void XmlTree::free() +{ + if (!theCollection) + destroy(); +} + + #ifndef EMBEDED_TYPE /******************************************************************************* @@ -792,11 +802,21 @@ #endif if (haveReference()) - GET_STORE().unregisterNode(this); + GET_STORE().unregisterReferenceToUnusedNode(this); delete this; } +/******************************************************************************* + +********************************************************************************/ +void XmlNode::unregisterReferencesToDeletedSubtree() +{ + if (haveReference()) + GET_STORE().unregisterReferenceToDeletedNode(this); +} + + ///////////////////////////////////////////////////////////////////////////////// // // @@ -1635,6 +1655,23 @@ } +/******************************************************************************* + +********************************************************************************/ +void InternalNode::unregisterReferencesToDeletedSubtree() +{ + std::for_each( + childrenBegin(), childrenEnd(), + std::mem_fun(&XmlNode::unregisterReferencesToDeletedSubtree)); + + std::for_each( + attrsBegin(), attrsEnd(), + std::mem_fun(&XmlNode::unregisterReferencesToDeletedSubtree)); + + XmlNode::unregisterReferencesToDeletedSubtree(); +} + + ///////////////////////////////////////////////////////////////////////////////// // // // class DocumentNode // === modified file 'src/store/naive/node_items.h' --- src/store/naive/node_items.h 2012-03-28 23:58:23 +0000 +++ src/store/naive/node_items.h 2012-04-04 15:35:31 +0000 @@ -211,6 +211,8 @@ void free(); + void destroy() throw(); + long getRefCount() const { return theRefCount; } long& getRefCount() { return theRefCount; } @@ -574,6 +576,8 @@ bool isConnectorNode() const { return (theFlags & IsConnectorNode) != 0; } + void unregisterReferencesToDeletedSubtree(); + #ifndef ZORBA_NO_FULL_TEXT FTTokenIterator_t getTokens( TokenizerProvider const&, @@ -860,6 +864,8 @@ void finalizeNode(); + void unregisterReferencesToDeletedSubtree(); + protected: csize findChild(const XmlNode* child) const; === modified file 'src/store/naive/pul_primitives.cpp' --- src/store/naive/pul_primitives.cpp 2012-03-28 17:56:59 +0000 +++ src/store/naive/pul_primitives.cpp 2012-04-04 15:35:31 +0000 @@ -155,6 +155,9 @@ { theParent->deleteChild(*this); } + + static_cast<zorba::simplestore::XmlNode*>(theTarget.getp()) + ->unregisterReferencesToDeletedSubtree(); } === modified file 'src/store/naive/simple_store.cpp' --- src/store/naive/simple_store.cpp 2012-03-28 23:58:23 +0000 +++ src/store/naive/simple_store.cpp 2012-04-04 15:35:31 +0000 @@ -343,7 +343,7 @@ @param node XDM node @return whether the node was registered or not. ********************************************************************************/ -bool SimpleStore::unregisterNode(XmlNode* node) +bool SimpleStore::unregisterReferenceToUnusedNode(XmlNode* node) { if (!node->haveReference()) return false; @@ -366,6 +366,34 @@ } } +/******************************************************************************* + Does nothing in the simple store. + + @param node XDM node + @return whether the node was registered or not. +********************************************************************************/ +bool SimpleStore::unregisterReferenceToDeletedNode(XmlNode* node) +{ + // Does nothing, since there is no persistency layer. A deleted node can still + // be retrieved with a reference, so its reference may not be removed from the + // cache. + // Merely returns true if entry found, false otherwise. + + if (!node->haveReference()) + return false; + + NodeRefMap::iterator resIt; + + if ((resIt = theNodeToReferencesMap.find(node)) != theNodeToReferencesMap.end()) + { + return true; + } + else + { + return false; + } +} + } // namespace simplestore } // namespace zorba === modified file 'src/store/naive/simple_store.h' --- src/store/naive/simple_store.h 2012-03-28 23:58:23 +0000 +++ src/store/naive/simple_store.h 2012-04-04 15:35:31 +0000 @@ -94,7 +94,9 @@ void destroyTreeIdGeneratorFactory(TreeIdGeneratorFactory* g) const; - bool unregisterNode(XmlNode* node); + bool unregisterReferenceToUnusedNode(XmlNode* node); + + bool unregisterReferenceToDeletedNode(XmlNode* node); // // Store api methods === modified file 'src/store/naive/store.h' --- src/store/naive/store.h 2012-03-28 22:09:36 +0000 +++ src/store/naive/store.h 2012-04-04 15:35:31 +0000 @@ -413,7 +413,12 @@ virtual bool getNodeByReference(store::Item_t& result, const zstring& ref) = 0; - virtual bool unregisterNode(XmlNode* node) = 0; + // Unregisters a reference to an unused node (upon its destruction in + // the memory). + virtual bool unregisterReferenceToUnusedNode(XmlNode* node) = 0; + + // Unregisters a reference to a node that was deleted (by XQUF). + virtual bool unregisterReferenceToDeletedNode(XmlNode* node) = 0; /*----------------------- Temp Sequence Management ---------------------------*/ public:
-- Mailing list: https://launchpad.net/~zorba-coders Post to : zorba-coders@lists.launchpad.net Unsubscribe : https://launchpad.net/~zorba-coders More help : https://help.launchpad.net/ListHelp