From 6321098414fc6dcdb6b27bb8d43e7ea1cc10c986 Mon Sep 17 00:00:00 2001 From: Alberto Massari <amassari@apache.org> Date: Tue, 14 Nov 2006 19:41:33 +0000 Subject: [PATCH] Minor performance improvement git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@474935 13f79535-47bb-0310-9956-ffa450edef68 --- src/xercesc/util/BitSet.cpp | 48 ++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/xercesc/util/BitSet.cpp b/src/xercesc/util/BitSet.cpp index e141fb79d..dec69adc8 100644 --- a/src/xercesc/util/BitSet.cpp +++ b/src/xercesc/util/BitSet.cpp @@ -236,35 +236,35 @@ unsigned int BitSet::hash(const unsigned int hashModulus) const // --------------------------------------------------------------------------- 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 -- GitLab