Author: amassari
Date: Tue Aug 25 13:48:09 2009
New Revision: 807630
URL: http://svn.apache.org/viewvc?rev=807630&view=rev
Log:
Fixed memory leak; added optimization to the bitfield enumerator
Modified:
xerces/c/trunk/src/xercesc/validators/common/CMStateSet.hpp
xerces/c/trunk/src/xercesc/validators/common/DFAContentModel.cpp
xerces/c/trunk/tests/src/DOM/DOMTest/DTest.cpp
Modified: xerces/c/trunk/src/xercesc/validators/common/CMStateSet.hpp
URL:
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/validators/common/CMStateSet.hpp?rev=807630&r1=807629&r2=807630&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/validators/common/CMStateSet.hpp (original)
+++ xerces/c/trunk/src/xercesc/validators/common/CMStateSet.hpp Tue Aug 25
13:48:09 2009
@@ -58,7 +58,7 @@
// fMemoryManager
// The memory manager used to allocate and deallocate memory
//
- XMLSize_t fArraySize;
+ XMLSize_t fArraySize;
XMLInt32** fBitArray;
MemoryManager* fMemoryManager;
};
@@ -145,6 +145,7 @@
if(fDynamicBuffer->fBitArray[index]!=NULL)
fDynamicBuffer->fMemoryManager->deallocate(fDynamicBuffer->fBitArray[index]);
}
+
fDynamicBuffer->fMemoryManager->deallocate(fDynamicBuffer->fBitArray);
fDynamicBuffer->fMemoryManager->deallocate(fDynamicBuffer);
}
}
@@ -458,7 +459,7 @@
// the memory
//
// -----------------------------------------------------------------------
- XMLSize_t fBitCount;
+ XMLSize_t fBitCount;
XMLInt32 fBits[CMSTATE_CACHED_INT32_SIZE];
CMDynamicBuffer* fDynamicBuffer;
@@ -468,12 +469,29 @@
class CMStateSetEnumerator : public XMemory
{
public:
- CMStateSetEnumerator(const CMStateSet* toEnum) :
+ CMStateSetEnumerator(const CMStateSet* toEnum, XMLSize_t start = 0) :
fToEnum(toEnum),
fIndexCount((XMLSize_t)-1),
fLastValue(0)
{
+ // if a starting bit is specified, place fIndexCount at the beginning
of the previous 32 bit area
+ // so the findNext moves to the one where 'start' is located
+ if(start > 32)
+ fIndexCount = (start/32 - 1) * 32;
findNext();
+ // if we found data, and fIndexCount is still pointing to the area
where 'start' is located, erase the bits before 'start'
+ if(hasMoreElements() && fIndexCount < start)
+ {
+ for(XMLSize_t i=0;i< (start - fIndexCount);i++)
+ {
+ XMLInt32 mask=(1UL << i);
+ if(fLastValue & mask)
+ fLastValue &= ~mask;
+ }
+ // in case the 32 bit area contained only bits before 'start',
advance
+ if(fLastValue==0)
+ findNext();
+ }
}
bool hasMoreElements()
@@ -536,7 +554,7 @@
}
const CMStateSet* fToEnum;
- XMLSize_t fIndexCount;
+ XMLSize_t fIndexCount;
XMLInt32 fLastValue;
};
Modified: xerces/c/trunk/src/xercesc/validators/common/DFAContentModel.cpp
URL:
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/validators/common/DFAContentModel.cpp?rev=807630&r1=807629&r2=807630&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/validators/common/DFAContentModel.cpp (original)
+++ xerces/c/trunk/src/xercesc/validators/common/DFAContentModel.cpp Tue Aug 25
13:48:09 2009
@@ -1066,17 +1066,15 @@
// every time we raise the lower marker we know it will
true also for the next bits, so
// the next binary search will not start from 1 but from
this index
unsigned int lowIndex = 1;
- CMStateSetEnumerator enumBits(setT);
+ // Start the enumerator from the first index in the sorted
list of places,
+ // as nothing before that point will match
+ CMStateSetEnumerator enumBits(setT, fLeafIndexes[1]);
while(enumBits.hasMoreElements())
{
unsigned int bitIndex=enumBits.nextElement();
- // if this leaf has an index less than the first index
in the sorted list of places,
- // it cannot be here, so avoid starting the binary
search
- if(bitIndex < fLeafIndexes[1])
- continue;
// if this leaf is greater than the last index in the
sorted list of places,
// nothing can be found from now on, so get out of here
- else if(bitIndex > fLeafIndexes[fNumItems])
+ if(bitIndex > fLeafIndexes[fNumItems])
break;
// Check if this leaf index (DFA position) is in the
current set
Modified: xerces/c/trunk/tests/src/DOM/DOMTest/DTest.cpp
URL:
http://svn.apache.org/viewvc/xerces/c/trunk/tests/src/DOM/DOMTest/DTest.cpp?rev=807630&r1=807629&r2=807630&view=diff
==============================================================================
--- xerces/c/trunk/tests/src/DOM/DOMTest/DTest.cpp (original)
+++ xerces/c/trunk/tests/src/DOM/DOMTest/DTest.cpp Tue Aug 25 13:48:09 2009
@@ -5704,6 +5704,26 @@
OK = false;
}
+ // test the enumerator with a non-default start
+ CMStateSetEnumerator enumT2a(&setT2, CMSTATE_BITFIELD_CHUNK/2);
+ if(!enumT2a.hasMoreElements() || enumT2a.nextElement()!=
(CMSTATE_BITFIELD_CHUNK/2))
+ {
+ fprintf(stderr, "bitset test failed at line %i\n", __LINE__);
+ OK = false;
+ }
+ CMStateSetEnumerator enumT2b(&setT2, CMSTATE_BITFIELD_CHUNK/2+2);
+ if(!enumT2b.hasMoreElements() || enumT2b.nextElement()!=
(CMSTATE_BITFIELD_CHUNK-1))
+ {
+ fprintf(stderr, "bitset test failed at line %i\n", __LINE__);
+ OK = false;
+ }
+ CMStateSetEnumerator enumT2c(&setT2, 2*CMSTATE_BITFIELD_CHUNK);
+ if(!enumT2c.hasMoreElements() || enumT2c.nextElement()!=
(2*CMSTATE_BITFIELD_CHUNK))
+ {
+ fprintf(stderr, "bitset test failed at line %i\n", __LINE__);
+ OK = false;
+ }
+
// this tests the hash generator
CMStateSet setT3(3 * CMSTATE_BITFIELD_CHUNK), setT4(3 *
CMSTATE_BITFIELD_CHUNK);
// these two sets will have a single bit set at the beginning of a chunk
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]