From a52bee34d41b49cc8a114435907c09685e1528d0 Mon Sep 17 00:00:00 2001
From: David Abram Cargill <cargilld@apache.org>
Date: Thu, 18 Nov 2004 01:35:20 +0000
Subject: [PATCH] Performance improvement to utility classes from Christian
 Will.  Avoid unnecessary checks and replace with assert calls.

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@176203 13f79535-47bb-0310-9956-ffa450edef68
---
 src/xercesc/dom/impl/DOMDeepNodeListPool.c | 10 +++++-----
 src/xercesc/util/NameIdPool.c              | 11 ++++++-----
 src/xercesc/util/RefHash2KeysTableOf.c     | 17 ++++++++---------
 src/xercesc/util/RefHash3KeysIdPool.c      | 10 ++++++----
 src/xercesc/util/RefHashTableOf.c          | 19 +++++++++----------
 src/xercesc/util/ValueHashTableOf.c        | 13 +++++++------
 src/xercesc/util/XMLString.cpp             | 18 ++++++++----------
 7 files changed, 49 insertions(+), 49 deletions(-)

diff --git a/src/xercesc/dom/impl/DOMDeepNodeListPool.c b/src/xercesc/dom/impl/DOMDeepNodeListPool.c
index 3037f75a5..5d6f59760 100644
--- a/src/xercesc/dom/impl/DOMDeepNodeListPool.c
+++ b/src/xercesc/dom/impl/DOMDeepNodeListPool.c
@@ -27,6 +27,8 @@
 #include <xercesc/dom/impl/DOMDeepNodeListPool.hpp>
 #endif
 
+#include <assert.h>
+
 XERCES_CPP_NAMESPACE_BEGIN
 
 
@@ -362,8 +364,7 @@ findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* con
 {
     // Hash the key
     hashVal = fHash->getHashVal(key1, fHashModulus, fMemoryManager);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     // Search that bucket for the key
     DOMDeepNodeListPoolTableBucketElem<TVal>* curElem = fBucketList[hashVal];
@@ -398,9 +399,8 @@ findBucketElem(const void* const key1, const XMLCh* const key2, const XMLCh* con
 {
     // Hash the key
     hashVal = fHash->getHashVal(key1, fHashModulus, fMemoryManager);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
-
+    assert(hashVal < fHashModulus);
+    
     // Search that bucket for the key
     const DOMDeepNodeListPoolTableBucketElem<TVal>* curElem = fBucketList[hashVal];
     while (curElem)
diff --git a/src/xercesc/util/NameIdPool.c b/src/xercesc/util/NameIdPool.c
index 04f28b4c2..873f14cad 100644
--- a/src/xercesc/util/NameIdPool.c
+++ b/src/xercesc/util/NameIdPool.c
@@ -16,6 +16,9 @@
 
 /**
  * $Log$
+ * Revision 1.10  2004/11/18 01:35:20  cargilld
+ * Performance improvement to utility classes from Christian Will.  Avoid unnecessary checks and replace with assert calls.
+ *
  * Revision 1.9  2004/09/08 13:56:22  peiyongz
  * Apache License Version 2.0
  *
@@ -70,6 +73,7 @@
 #include <xercesc/util/IllegalArgumentException.hpp>
 #include <xercesc/util/NoSuchElementException.hpp>
 #include <xercesc/util/RuntimeException.hpp>
+#include <assert.h>
 
 XERCES_CPP_NAMESPACE_BEGIN
 
@@ -300,8 +304,7 @@ findBucketElem(const XMLCh* const key, unsigned int& hashVal)
     // Hash the key
     hashVal = XMLString::hash(key, fHashModulus, fMemoryManager);
 
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Pool_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     // Search that bucket for the key
     NameIdPoolBucketElem<TElem>* curElem = fBucketList[hashVal];
@@ -320,9 +323,7 @@ findBucketElem(const XMLCh* const key, unsigned int& hashVal) const
 {
     // Hash the key
     hashVal = XMLString::hash(key, fHashModulus, fMemoryManager);
-
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Pool_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     // Search that bucket for the key
     const NameIdPoolBucketElem<TElem>* curElem = fBucketList[hashVal];
diff --git a/src/xercesc/util/RefHash2KeysTableOf.c b/src/xercesc/util/RefHash2KeysTableOf.c
index 81d338eea..9ba5c40bc 100644
--- a/src/xercesc/util/RefHash2KeysTableOf.c
+++ b/src/xercesc/util/RefHash2KeysTableOf.c
@@ -16,6 +16,9 @@
 
 /**
  * $Log$
+ * Revision 1.12  2004/11/18 01:35:20  cargilld
+ * Performance improvement to utility classes from Christian Will.  Avoid unnecessary checks and replace with assert calls.
+ *
  * Revision 1.11  2004/09/22 11:14:22  amassari
  * Reorder initialization of variables in constructor
  *
@@ -76,6 +79,7 @@
 #endif
 
 #include <xercesc/util/NullPointerException.hpp>
+#include <assert.h>
 
 XERCES_CPP_NAMESPACE_BEGIN
 
@@ -218,9 +222,7 @@ template <class TVal> void RefHash2KeysTableOf<TVal>::transferElement(const void
 {
     // Hash the key
     unsigned int hashVal = fHash->getHashVal(key1, fHashModulus);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
-
+    assert(hashVal < fHashModulus);
     //
     //  Search the given bucket for this key. Keep up with the previous
     //  element so we can patch around it.
@@ -337,8 +339,7 @@ findBucketElem(const void* const key1, const int key2, unsigned int& hashVal)
 {
     // Hash the key
     hashVal = fHash->getHashVal(key1, fHashModulus, fMemoryManager);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     // Search that bucket for the key
     RefHash2KeysTableBucketElem<TVal>* curElem = fBucketList[hashVal];
@@ -357,8 +358,7 @@ findBucketElem(const void* const key1, const int key2, unsigned int& hashVal) co
 {
     // Hash the key
     hashVal = fHash->getHashVal(key1, fHashModulus, fMemoryManager);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     // Search that bucket for the key
     const RefHash2KeysTableBucketElem<TVal>* curElem = fBucketList[hashVal];
@@ -378,8 +378,7 @@ removeBucketElem(const void* const key1, const int key2, unsigned int& hashVal)
 {
     // Hash the key
     hashVal = fHash->getHashVal(key1, fHashModulus);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     //
     //  Search the given bucket for this key. Keep up with the previous
diff --git a/src/xercesc/util/RefHash3KeysIdPool.c b/src/xercesc/util/RefHash3KeysIdPool.c
index 741d024d1..9fb9294e1 100644
--- a/src/xercesc/util/RefHash3KeysIdPool.c
+++ b/src/xercesc/util/RefHash3KeysIdPool.c
@@ -16,6 +16,9 @@
 
 /**
  * $Log$
+ * Revision 1.14  2004/11/18 01:35:20  cargilld
+ * Performance improvement to utility classes from Christian Will.  Avoid unnecessary checks and replace with assert calls.
+ *
  * Revision 1.13  2004/09/08 13:56:22  peiyongz
  * Apache License Version 2.0
  *
@@ -79,6 +82,7 @@
 #endif
 
 #include <xercesc/util/NullPointerException.hpp>
+#include <assert.h>
 
 XERCES_CPP_NAMESPACE_BEGIN
 
@@ -390,8 +394,7 @@ findBucketElem(const void* const key1, const int key2, const int key3, unsigned
 {
     // Hash the key
     hashVal = fHash->getHashVal(key1, fHashModulus, fMemoryManager);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     // Search that bucket for the key
     RefHash3KeysTableBucketElem<TVal>* curElem = fBucketList[hashVal];
@@ -410,8 +413,7 @@ findBucketElem(const void* const key1, const int key2, const int key3, unsigned
 {
     // Hash the key
     hashVal = fHash->getHashVal(key1, fHashModulus);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     // Search that bucket for the key
     const RefHash3KeysTableBucketElem<TVal>* curElem = fBucketList[hashVal];
diff --git a/src/xercesc/util/RefHashTableOf.c b/src/xercesc/util/RefHashTableOf.c
index fccb911bf..1c49592b1 100644
--- a/src/xercesc/util/RefHashTableOf.c
+++ b/src/xercesc/util/RefHashTableOf.c
@@ -16,6 +16,9 @@
 
 /**
  * $Log$
+ * Revision 1.17  2004/11/18 01:35:20  cargilld
+ * Performance improvement to utility classes from Christian Will.  Avoid unnecessary checks and replace with assert calls.
+ *
  * Revision 1.16  2004/09/08 13:56:23  peiyongz
  * Apache License Version 2.0
  *
@@ -113,6 +116,7 @@
 #endif
 
 #include <xercesc/util/NullPointerException.hpp>
+#include <assert.h>
 
 XERCES_CPP_NAMESPACE_BEGIN
 
@@ -271,8 +275,7 @@ orphanKey(const void* const key)
     // Hash the key
     TVal* retVal = 0;
     unsigned int hashVal = fHash->getHashVal(key, fHashModulus, fMemoryManager);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     //
     //  Search the given bucket for this key. Keep up with the previous
@@ -476,8 +479,7 @@ template <class TVal> void RefHashTableOf<TVal>::rehash()
             nextElem = curElem->fNext;
 
             unsigned int hashVal = fHash->getHashVal(curElem->fKey, fHashModulus, fMemoryManager);
-            if (hashVal > fHashModulus)
-                ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+            assert(hashVal < fHashModulus);
             
             RefHashTableBucketElem<TVal>* newHeadElem = fBucketList[hashVal];
             
@@ -498,8 +500,7 @@ findBucketElem(const void* const key, unsigned int& hashVal)
 {
     // Hash the key
     hashVal = fHash->getHashVal(key, fHashModulus, fMemoryManager);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     // Search that bucket for the key
     RefHashTableBucketElem<TVal>* curElem = fBucketList[hashVal];
@@ -518,8 +519,7 @@ findBucketElem(const void* const key, unsigned int& hashVal) const
 {
     // Hash the key
     hashVal = fHash->getHashVal(key, fHashModulus, fMemoryManager);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     // Search that bucket for the key
     const RefHashTableBucketElem<TVal>* curElem = fBucketList[hashVal];
@@ -539,8 +539,7 @@ removeBucketElem(const void* const key, unsigned int& hashVal)
 {
     // Hash the key
     hashVal = fHash->getHashVal(key, fHashModulus, fMemoryManager);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     //
     //  Search the given bucket for this key. Keep up with the previous
diff --git a/src/xercesc/util/ValueHashTableOf.c b/src/xercesc/util/ValueHashTableOf.c
index 313430106..2e9ce6325 100644
--- a/src/xercesc/util/ValueHashTableOf.c
+++ b/src/xercesc/util/ValueHashTableOf.c
@@ -16,6 +16,9 @@
 
 /**
  * $Log$
+ * Revision 1.10  2004/11/18 01:35:20  cargilld
+ * Performance improvement to utility classes from Christian Will.  Avoid unnecessary checks and replace with assert calls.
+ *
  * Revision 1.9  2004/09/08 13:56:23  peiyongz
  * Apache License Version 2.0
  *
@@ -48,6 +51,7 @@
 #endif
 
 #include <xercesc/util/NullPointerException.hpp>
+#include <assert.h>
 
 XERCES_CPP_NAMESPACE_BEGIN
 
@@ -219,8 +223,7 @@ findBucketElem(const void* const key, unsigned int& hashVal)
 {
     // Hash the key
     hashVal = fHash->getHashVal(key, fHashModulus, fMemoryManager);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     // Search that bucket for the key
     ValueHashTableBucketElem<TVal>* curElem = fBucketList[hashVal];
@@ -239,8 +242,7 @@ findBucketElem(const void* const key, unsigned int& hashVal) const
 {
     // Hash the key
     hashVal = fHash->getHashVal(key, fHashModulus, fMemoryManager);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     // Search that bucket for the key
     const ValueHashTableBucketElem<TVal>* curElem = fBucketList[hashVal];
@@ -260,8 +262,7 @@ removeBucketElem(const void* const key, unsigned int& hashVal)
 {
     // Hash the key
     hashVal = fHash->getHashVal(key, fHashModulus);
-    if (hashVal > fHashModulus)
-        ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::HshTbl_BadHashFromKey, fMemoryManager);
+    assert(hashVal < fHashModulus);
 
     //
     //  Search the given bucket for this key. Keep up with the previous
diff --git a/src/xercesc/util/XMLString.cpp b/src/xercesc/util/XMLString.cpp
index e7267be88..32553826d 100644
--- a/src/xercesc/util/XMLString.cpp
+++ b/src/xercesc/util/XMLString.cpp
@@ -26,6 +26,7 @@
 #include <ctype.h>
 #include <stdlib.h>
 #include <errno.h>
+#include <assert.h>
 
 #include <xercesc/util/XMLString.hpp>
 #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
@@ -296,10 +297,9 @@ void XMLString::cut(        XMLCh* const    toCutFrom
 
 unsigned int XMLString::hash(   const   char* const     tohash
                                 , const unsigned int    hashModulus
-                                , MemoryManager* const  manager)
+                                , MemoryManager* const)
 {    
-    if (!hashModulus)
-        ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::Pool_ZeroModulus, manager);
+    assert(hashModulus);
 
     unsigned int hashVal = 0;
     if (tohash) {
@@ -1099,10 +1099,9 @@ bool XMLString::copyNString(        XMLCh* const    target
 
 unsigned int XMLString::hash(   const   XMLCh* const    tohash
                                 , const unsigned int    hashModulus
-                                , MemoryManager* const  manager)
-{    
-    if (!hashModulus)
-        ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::Pool_ZeroModulus, manager);
+                                , MemoryManager* const)
+{  
+    assert(hashModulus);
 
     unsigned int hashVal = 0;
     if (tohash) {
@@ -1195,10 +1194,9 @@ int XMLString::patternMatch(  const XMLCh* const    toSearch
 unsigned int XMLString::hashN(  const   XMLCh* const    tohash
                                 , const unsigned int    n
                                 , const unsigned int    hashModulus
-                                , MemoryManager* const  manager)
+                                , MemoryManager* const)
 {
-    if (!hashModulus)
-        ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::Pool_ZeroModulus, manager);
+    assert(hashModulus);
 
     unsigned int hashVal = 0;
     if (tohash) {
-- 
GitLab