mrglavas    2004/03/27 20:05:14

  Modified:    java/src/org/apache/xerces/impl/dtd DTDGrammar.java
  Log:
  Performance: Use String.hashCode() instead of using our own

  hash method. The keys stored in instances of these hashtables

  are interned strings (also in the SymbolTable) so we get the

  hashcode for free since it is cached after it has been computed.
  
  Revision  Changes    Path
  1.27      +3 -23     xml-xerces/java/src/org/apache/xerces/impl/dtd/DTDGrammar.java
  
  Index: DTDGrammar.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/DTDGrammar.java,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -u -r1.26 -r1.27
  --- DTDGrammar.java   24 Feb 2004 22:48:17 -0000      1.26
  +++ DTDGrammar.java   28 Mar 2004 04:05:13 -0000      1.27
  @@ -2610,7 +2610,6 @@
           //
           // Constants
           //
  -        public static final boolean UNIQUE_STRINGS = true;
       
           /** Initial bucket size (4). */
           private static final int INITIAL_BUCKET_SIZE = 4;
  @@ -2632,7 +2631,7 @@
           public void put(String key, int value) {
   
               // REVISIT: Why +2? -Ac
  -            int hash = (hash(key)+2) % HASHTABLE_SIZE;
  +            int hash = (key.hashCode() & 0x7FFFFFFF) % HASHTABLE_SIZE;
               Object[] bucket = fHashTable[hash];
   
               if (bucket == null) {
  @@ -2675,7 +2674,7 @@
   
           /** Returns the value associated with the specified key tuple. */
           public int get(String key) {
  -            int hash = (hash(key)+2) % HASHTABLE_SIZE;
  +            int hash = (key.hashCode() & 0x7FFFFFFF) % HASHTABLE_SIZE;
               Object[] bucket = fHashTable[hash];
   
               if (bucket == null) {
  @@ -2693,25 +2692,6 @@
               return -1;
   
           } // get(int,String,String)
  -
  -        //
  -        // Protected methods
  -        //
  -
  -        /** Returns a hash value for the specified symbol. */
  -        protected int hash(String symbol) {
  -
  -            if (symbol == null) {
  -                return 0;
  -            }
  -            int code = 0;
  -            int length = symbol.length();
  -            for (int i = 0; i < length; i++) {
  -                code = code * 37 + symbol.charAt(i);
  -            }
  -            return code & 0x7FFFFFF;
  -
  -        } // hash(String):int
   
       }  // class QNameHashtable
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to