diff --git a/src/xercesc/util/BitSet.cpp b/src/xercesc/util/BitSet.cpp
index e141fb79d14f2b733f09e72f509aa12fa0c7b939..dec69adc853e771cbb38a3fe8ae3a964dbc6583f 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