You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by lm...@apache.org on 2001/07/20 19:27:54 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/utils SymbolCache.java

lmartin     01/07/20 10:27:54

  Modified:    java/src/org/apache/xerces/utils SymbolCache.java
  Log:
  Performance patches related to array resizing - submitted by Henry Zongaro
  
  Revision  Changes    Path
  1.4       +73 -10    xml-xerces/java/src/org/apache/xerces/utils/SymbolCache.java
  
  Index: SymbolCache.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/utils/SymbolCache.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SymbolCache.java	2000/02/08 02:47:28	1.3
  +++ SymbolCache.java	2001/07/20 17:27:54	1.4
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -69,23 +69,85 @@
       public static final int INDEX_OFFSET = 1;
       public static final int NEXT_OFFSET = 2;
       public static final int CACHE_RECORD_SIZE = 3;
  -    //
  -    public static final int INITIAL_CACHE_RECORD_COUNT = 4; // start with 4 entries per level
  +
  +    // start with 4 entries per level on cache lines other than 0
  +    public static final int INITIAL_CACHE_RECORD_COUNT = 4;
  +
  +    // start with 85 entries on cache line 0 (85*3+1 = 256)
  +    public static final int HEAD_INITIAL_CACHE_RECORD_COUNT = 85;
       //
       public char[] fSymbolChars = new char[8192];
       public int fSymbolCharsOffset = 0;
  -    public int[][] fCacheLines = new int[8][];
  +    public int[][] fCacheLines = new int[256][];
       public int fCacheLineCount = 0;
  -    //
  -    //
  -    //
  +
  +/*
  + *
  + * A brief description of how a SymbolCache is organized:
  + *
  + *   The first entry in any fCacheLines[] array is a count of the number of
  + *   records stored in that array.  Subsequent entries are arranged in groups
  + *   of three:  a character value; the symbol handle, if this is the last
  + *   character in a symbol, or -1 otherwise; and a pointer to the next character
  + *   in the symbol, or -1 if there is none.  All symbol entries begin in
  + *   fCacheLines[0].
  + *
  + *   For example, if the symbols "help", "he:p", "hel", and "bob" are
  + *   entered, and have symbol indices 11, 22, 33 and 44, respectively, the
  + *   fCacheLines array will look something like this (ignoring zero elements):
  + *
  + *     fCacheLines[0] = {2, 'h', -1, 1, 'b', -1, 5}
  + *     fCacheLines[1] = {1, 'e', -1, 2}
  + *     fCacheLines[2] = {2, 'l', 33, 3, ':', -1, 4}
  + *     fCacheLines[3] = {1, 'p', 11, -1}
  + *     fCacheLines[4] = {1, 'p', 22, -1}
  + *     fCacheLines[5] = {1, 'o', -1, 6}
  + *     fCacheLines[6] = {1, 'b', 44, -1}
  + *
  + *   The initial character of every symbol is stored in fCacheLines[0].  Other
  + *   elements of fCacheLines contain records for characters that share common
  + *   prefixes.  For instance, fCacheLines[2] contains records for all symbols
  + *   that begin with "he".  Note also that the symbol "hel" has both a symbol
  + *   index and a pointer to the record containing the next character, as both
  + *   "hel" and "help" are symbols in the cache.
  + *
  + */
  +
  +/****
  +public void dumpCache() {
  +    System.out.println("fSymbolChars.length == "+fSymbolChars.length);
  +
  +    for (int i = 0; i < fSymbolCharsOffset; i++)
  +        System.out.println("fSymbolChars["+i+"] == "+fSymbolChars[i]);
  +
  +    for (int i = 0; i < fCacheLineCount; i++) {
  +        System.out.print("fCacheLines["+i+"] (num records == "+
  +                         fCacheLines[i][0]+") == {");
  +
  +        int offset = 1;
  +        for (int j = 0; j < fCacheLines[i][0]; j++) {
  +            System.out.print("{char="+
  +                 (new Character((char)fCacheLines[i][offset+CHAR_OFFSET]).
  +                                                                   toString())+
  +                             "; idx="+fCacheLines[i][offset+INDEX_OFFSET]+
  +                             "; next="+fCacheLines[i][offset+NEXT_OFFSET]+"}");
  +            offset += CACHE_RECORD_SIZE;
  +        }
  +        System.out.println("} - (Actual size == "+fCacheLines[i].length+")");
  +    }
  +}
  +****/
  +
       public SymbolCache() {
  -        fCacheLines[fCacheLineCount++] = new int[1+(INITIAL_CACHE_RECORD_COUNT*CACHE_RECORD_SIZE)];
  +        fCacheLines[fCacheLineCount++] =
  +                new int[1+(HEAD_INITIAL_CACHE_RECORD_COUNT*CACHE_RECORD_SIZE)];
       }
  +    //
       public void reset() {
           fSymbolCharsOffset = 0;
           fCacheLineCount = 0;
  -        fCacheLines[fCacheLineCount++] = new int[1+(INITIAL_CACHE_RECORD_COUNT*CACHE_RECORD_SIZE)];
  +        fCacheLines[fCacheLineCount++] =
  +                new int[1+(HEAD_INITIAL_CACHE_RECORD_COUNT*CACHE_RECORD_SIZE)];
       }
       //
       //
  @@ -96,7 +158,8 @@
       //
       // Symbol interfaces
       //
  -    public String createSymbol(int symbolHandle, int startOffset, int entry, int[] entries, int offset) {
  +    public String createSymbol(int symbolHandle, int startOffset, int entry,
  +                               int[] entries, int offset) {
           int slen = fSymbolCharsOffset - startOffset;
           String str = new String(fSymbolChars, startOffset, slen);
           try {
  
  
  

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