You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by am...@apache.org on 2006/11/14 20:41:34 UTC
svn commit: r474935 - /xerces/c/trunk/src/xercesc/util/BitSet.cpp
Author: amassari
Date: Tue Nov 14 11:41:33 2006
New Revision: 474935
URL: http://svn.apache.org/viewvc?view=rev&rev=474935
Log:
Minor performance improvement
Modified:
xerces/c/trunk/src/xercesc/util/BitSet.cpp
Modified: xerces/c/trunk/src/xercesc/util/BitSet.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/BitSet.cpp?view=diff&rev=474935&r1=474934&r2=474935
==============================================================================
--- xerces/c/trunk/src/xercesc/util/BitSet.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/BitSet.cpp Tue Nov 14 11:41:33 2006
@@ -236,35 +236,35 @@
// ---------------------------------------------------------------------------
void BitSet::ensureCapacity(const unsigned int size)
{
+ // If we have enough space, do nothing
+ if(fUnitLen * kBitsPerUnit >= size)
+ return;
+
// Calculate the units required to hold the passed bit count.
unsigned int unitsNeeded = size / kBitsPerUnit;
if (size % kBitsPerUnit)
unitsNeeded++;
- // If its more than we have, then reallocate
- if (unitsNeeded > fUnitLen)
- {
- // Regrow the unit length by at least the expansion unit
- if (unitsNeeded < (fUnitLen + kGrowBy))
- unitsNeeded = fUnitLen + kGrowBy;
-
- // Allocate the array, copy the old stuff, and zero the new stuff
- unsigned long* newBits = (unsigned long*) fMemoryManager->allocate
- (
- unitsNeeded * sizeof(unsigned long)
- ); //new unsigned long[unitsNeeded];
-
- unsigned int index;
- for (index = 0; index < fUnitLen; index++)
- newBits[index] = fBits[index];
-
- for (; index < unitsNeeded; index++)
- newBits[index] = 0;
-
- fMemoryManager->deallocate(fBits); //delete [] fBits;
- fBits = newBits;
- fUnitLen = unitsNeeded;
- }
+ // Regrow the unit length by at least the expansion unit
+ if (unitsNeeded < (fUnitLen + kGrowBy))
+ unitsNeeded = fUnitLen + kGrowBy;
+
+ // Allocate the array, copy the old stuff, and zero the new stuff
+ unsigned long* newBits = (unsigned long*) fMemoryManager->allocate
+ (
+ unitsNeeded * sizeof(unsigned long)
+ ); //new unsigned long[unitsNeeded];
+
+ unsigned int index;
+ for (index = 0; index < fUnitLen; index++)
+ newBits[index] = fBits[index];
+
+ for (; index < unitsNeeded; index++)
+ newBits[index] = 0;
+
+ fMemoryManager->deallocate(fBits); //delete [] fBits;
+ fBits = newBits;
+ fUnitLen = unitsNeeded;
}
XERCES_CPP_NAMESPACE_END
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org