You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by sa...@apache.org on 2001/11/06 20:21:31 UTC

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

sandygao    01/11/06 11:21:31

  Modified:    java/src/org/apache/xerces/util SymbolTable.java
  Log:
  Fixing bug [943]: whenever a string is added into SymbolTable, we internalize
  it using String#intern(), so that the strings passed to the application are java-internalized,
  and can be reference-compared with other java-internalized strings.
  
  Revision  Changes    Path
  1.3       +24 -24    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SymbolTable.java	2001/08/23 00:35:32	1.2
  +++ SymbolTable.java	2001/11/06 19:21:31	1.3
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 2000 The Apache Software Foundation.  All rights 
  + * Copyright (c) 2000 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -10,7 +10,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -18,7 +18,7 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:  
  + *    if any, must include the following acknowledgment:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgment may appear in the software itself,
  @@ -26,7 +26,7 @@
    *
    * 4. The names "Xerces" and "Apache Software Foundation" must
    *    not be used to endorse or promote products derived from this
  - *    software without prior written permission. For written 
  + *    software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache",
  @@ -74,7 +74,7 @@
    *  <li>
    *   Users of the symbol table can provide their own symbol hashing
    *   implementation. For example, a simple string hashing algorithm
  - *   may fail to produce a balanced set of hashcodes for symbols 
  + *   may fail to produce a balanced set of hashcodes for symbols
    *   that are <em>mostly</em> unique. Strings with similar leading
    *   characters are especially prone to this poor hashing behavior.
    *  </li>
  @@ -85,7 +85,7 @@
    * @author Stubs generated by DesignDoc on Wed Jun 07 11:58:44 PDT 2000
    * @author Andy Clark
    *
  - * @version $Id: SymbolTable.java,v 1.2 2001/08/23 00:35:32 lehors Exp $
  + * @version $Id: SymbolTable.java,v 1.3 2001/11/06 19:21:31 sandygao Exp $
    */
   public class SymbolTable {
   
  @@ -117,10 +117,10 @@
   
       /**
        * Adds the specified symbol to the symbol table and returns a
  -     * reference to the unique symbol. If the symbol already exists, 
  +     * reference to the unique symbol. If the symbol already exists,
        * the previous symbol reference is returned instead, in order
        * guarantee that symbol references remain unique.
  -     * 
  +     *
        * @param symbol The new symbol.
        */
       public String addSymbol(String symbol) {
  @@ -142,16 +142,16 @@
           // create new entry
           Entry entry = new Entry(symbol, fBuckets[bucket]);
           fBuckets[bucket] = entry;
  -        return symbol;
  +        return entry.symbol;
   
       } // addSymbol(String):String
   
       /**
        * Adds the specified symbol to the symbol table and returns a
  -     * reference to the unique symbol. If the symbol already exists, 
  +     * reference to the unique symbol. If the symbol already exists,
        * the previous symbol reference is returned instead, in order
        * guarantee that symbol references remain unique.
  -     * 
  +     *
        * @param buffer The buffer containing the new symbol.
        * @param offset The offset into the buffer of the new symbol.
        * @param length The length of the new symbol in the buffer.
  @@ -183,7 +183,7 @@
        * returned by this method must be identical to the value returned
        * by the <code>hash(char[],int,int)</code> method when called
        * with the character array that comprises the symbol string.
  -     * 
  +     *
        * @param symbol The symbol to hash.
        */
       public int hash(String symbol) {
  @@ -198,11 +198,11 @@
       } // hash(String):int
   
       /**
  -     * Returns a hashcode value for the specified symbol information. 
  +     * Returns a hashcode value for the specified symbol information.
        * The value returned by this method must be identical to the value
        * returned by the <code>hash(String)</code> method when called
        * with the string object created from the symbol information.
  -     * 
  +     *
        * @param buffer The character buffer containing the symbol.
        * @param offset The offset into the character buffer of the start
        *               of the symbol.
  @@ -218,14 +218,14 @@
   
       } // hash(char[],int,int):int
   
  -    /** 
  +    /**
        * Returns true if the symbol table already contains the specified
        * symbol.
        *
        * @param symbol The symbol to look for.
        */
       public boolean containsSymbol(String symbol) {
  -        
  +
           // search for identical symbol
           int bucket = hash(symbol) % TABLE_SIZE;
           int length = symbol.length();
  @@ -244,7 +244,7 @@
   
       } // containsSymbol(String):boolean
   
  -    /** 
  +    /**
        * Returns true if the symbol table already contains the specified
        * symbol.
        *
  @@ -288,7 +288,7 @@
           /** Symbol. */
           public String symbol;
   
  -        /** 
  +        /**
            * Symbol characters. This information is duplicated here for
            * comparison performance.
            */
  @@ -301,25 +301,25 @@
           // Constructors
           //
   
  -        /** 
  +        /**
            * Constructs a new entry from the specified symbol and next entry
  -         * reference. 
  +         * reference.
            */
           public Entry(String symbol, Entry next) {
  -            this.symbol = symbol;
  +            this.symbol = symbol.intern();
               characters = new char[symbol.length()];
               symbol.getChars(0, characters.length, characters, 0);
               this.next = next;
           }
   
  -        /** 
  +        /**
            * Constructs a new entry from the specified symbol information and
  -         * next entry reference. 
  +         * next entry reference.
            */
           public Entry(char[] ch, int offset, int length, Entry next) {
               characters = new char[length];
               System.arraycopy(ch, offset, characters, 0, length);
  -            symbol = new String(characters);
  +            symbol = new String(characters).intern();
               this.next = next;
           }
   
  
  
  

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