mrglavas    2005/03/14 15:09:35

  Modified:    java/src/org/apache/xerces/util SymbolTable.java
  Log:
  Improve performance of SymbolTable.addSymbol(String). In many instances the 
strings
  we pass into this method are already internalized. In such cases calling 
String.hashCode()
  will yield better performance than calculating a hash code ourselves. Updated 
hash(char[], int, int)
  so that it will yield the same result as String.hashCode().
  
  Revision  Changes    Path
  1.10      +7 -20     
xml-xerces/java/src/org/apache/xerces/util/SymbolTable.java
  
  Index: SymbolTable.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xerces/java/src/org/apache/xerces/util/SymbolTable.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SymbolTable.java  30 Jul 2004 22:10:54 -0000      1.9
  +++ SymbolTable.java  14 Mar 2005 23:09:35 -0000      1.10
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 2000-2002,2004 The Apache Software Foundation.
  + * Copyright 2000-2002,2004,2005 The Apache Software Foundation.
    * 
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -174,14 +174,8 @@
           
           // search for identical symbol
           int bucket = hash(symbol) % fTableSize;
  -        int length = symbol.length();
  -        OUTER: for (Entry entry = fBuckets[bucket]; entry != null; entry = 
entry.next) {
  -            if (length == entry.characters.length) {
  -                for (int i = 0; i < length; i++) {
  -                    if (symbol.charAt(i) != entry.characters[i]) {
  -                        continue OUTER;
  -                    }
  -                }
  +        for (Entry entry = fBuckets[bucket]; entry != null; entry = 
entry.next) {
  +            if (entry.symbol.equals(symbol)) {
                   return entry.symbol;
               }
           }
  @@ -248,14 +242,7 @@
        * @param symbol The symbol to hash.
        */
       public int hash(String symbol) {
  -
  -        int code = 0;
  -        int length = symbol.length();
  -        for (int i = 0; i < length; i++) {
  -            code = code * 37 + symbol.charAt(i);
  -        }
  -        return code & 0x7FFFFFF;
  -
  +        return symbol.hashCode() & 0x7FFFFFF;
       } // hash(String):int
   
       /**
  @@ -272,8 +259,8 @@
       public int hash(char[] buffer, int offset, int length) {
   
           int code = 0;
  -        for (int i = 0; i < length; i++) {
  -            code = code * 37 + buffer[offset + i];
  +        for (int i = 0; i < length; ++i) {
  +            code = code * 31 + buffer[offset + i];
           }
           return code & 0x7FFFFFF;
   
  
  
  

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

Reply via email to