You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2001/10/01 21:36:18 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/util SymbolHash.java

neilg       01/10/01 12:36:18

  Modified:    java/src/org/apache/xerces/util SymbolHash.java
  Log:
  make Symbolhash more robust vis. null uris and add some utility methods.
  
  Revision  Changes    Path
  1.3       +27 -14    xml-xerces/java/src/org/apache/xerces/util/SymbolHash.java
  
  Index: SymbolHash.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/util/SymbolHash.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SymbolHash.java	2001/09/19 15:56:14	1.2
  +++ SymbolHash.java	2001/10/01 19:36:18	1.3
  @@ -66,7 +66,7 @@
    * The hash code uses the same algorithm as SymbolTable class.
    * 
    * @author Elena Litani
  - * @version $Id: SymbolHash.java,v 1.2 2001/09/19 15:56:14 elena Exp $
  + * @version $Id: SymbolHash.java,v 1.3 2001/10/01 19:36:18 neilg Exp $
    */
   public class SymbolHash {
   
  @@ -138,7 +138,7 @@
        */
       public String put(QName qName, Object value) {
   
  -        String key = qName.uri.concat(qName.localpart);
  +        String key = (qName.uri == null)?qName.localpart:qName.uri.concat(qName.localpart);
   
           // search for identical key
           int bucket = hash(key) % fTableSize;
  @@ -164,6 +164,13 @@
           return null;
       }
   
  +    // this tries to save a bit of GC'ing by at least keeping the fBuckets array around.
  +    public void clear() {
  +        for (int i=0; i<fTableSize; i++) {
  +            fBuckets[i] = new Entry();
  +        }
  +    } // clear():  void
  +
       public Object get (QName qName){
   
           String key = qName.uri.concat(qName.localpart);
  @@ -181,7 +188,7 @@
           // search for identical key
           int length = key.length();
           OUTER: for (Entry entry = fBuckets[bucket]; entry != null; entry = entry.next) {
  -            if (length == entry.characters.length) {
  +            if (entry.characters != null && length == entry.characters.length) {
                   for (int i = 0; i < length; i++) {
                       if (key.charAt(i) != entry.characters[i]) {
                           continue OUTER;
  @@ -223,12 +230,12 @@
        * in a linked list.
        */
       protected static final class Entry {
  -	/**
  -        * key is a name or QName 
  -        */
  -	public String key;
  +	    /**
  +         * key is a name or QName 
  +         */
  +	    public String key;
   
  -	public Object value;
  +	    public Object value;
   	
           /** 
            * key characters. This information is duplicated here for
  @@ -240,14 +247,20 @@
           public Entry next;
   
   
  -	public Entry(String key, Object value, Entry next) {
  -	    this.key = key;
  -	    this.value = value;
  -	    this.next = next;
  +        public Entry() {
  +            key = null;
  +            value = null;
  +            characters = null;
  +            next = null;
  +        }
  +	    public Entry(String key, Object value, Entry next) {
  +	        this.key = key;
  +	        this.value = value;
  +	        this.next = next;
               characters = new char[key.length()];
               key.getChars(0, characters.length, characters, 0);
  -	}
  -    }
  +	    }
  +    } // entry
   
   } // class SymbolHash
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org