Changeset 12192


Ignore:
Timestamp:
10/13/09 19:32:46 (12 years ago)
Author:
vvoutilainen
Message:

Patch by Douglas R. Miles to improve performance after CHAR_MAX
was increased from 255 to 64k.

Location:
trunk/abcl/src/org/armedbear/lisp
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/FaslReadtable.java

    r12044 r12192  
    4444    protected void initialize()
    4545    {
     46      Byte[] syntax = this.syntax.constants;
    4647        syntax[9]    = SYNTAX_TYPE_WHITESPACE; // tab
    4748        syntax[10]   = SYNTAX_TYPE_WHITESPACE; // linefeed
     
    6364        syntax['|']  = SYNTAX_TYPE_MULTIPLE_ESCAPE;
    6465
     66        LispObject[] readerMacroFunctions = this.readerMacroFunctions.constants;
    6567        readerMacroFunctions[';']  = FaslReader.FASL_READ_COMMENT;
    6668        readerMacroFunctions['"']  = FaslReader.FASL_READ_STRING;
     
    7577
    7678        DispatchTable dt = new DispatchTable();
    77         dt.functions['(']  = FaslReader.FASL_SHARP_LEFT_PAREN;
    78         dt.functions['*']  = FaslReader.FASL_SHARP_STAR;
    79         dt.functions['.']  = FaslReader.FASL_SHARP_DOT;
    80         dt.functions[':']  = FaslReader.FASL_SHARP_COLON;
    81         dt.functions['A']  = FaslReader.FASL_SHARP_A;
    82         dt.functions['B']  = FaslReader.FASL_SHARP_B;
    83         dt.functions['C']  = FaslReader.FASL_SHARP_C;
    84         dt.functions['O']  = FaslReader.FASL_SHARP_O;
    85         dt.functions['P']  = FaslReader.FASL_SHARP_P;
    86         dt.functions['R']  = FaslReader.FASL_SHARP_R;
    87         dt.functions['S']  = FaslReader.FASL_SHARP_S;
    88         dt.functions['X']  = FaslReader.FASL_SHARP_X;
    89         dt.functions['\''] = FaslReader.FASL_SHARP_QUOTE;
    90         dt.functions['\\'] = FaslReader.FASL_SHARP_BACKSLASH;
    91         dt.functions['|']  = FaslReader.FASL_SHARP_VERTICAL_BAR;
    92         dt.functions[')']  = FaslReader.FASL_SHARP_ILLEGAL;
    93         dt.functions['<']  = FaslReader.FASL_SHARP_ILLEGAL;
    94         dt.functions[' ']  = FaslReader.FASL_SHARP_ILLEGAL;
    95         dt.functions[8]    = FaslReader.FASL_SHARP_ILLEGAL; // backspace
    96         dt.functions[9]    = FaslReader.FASL_SHARP_ILLEGAL; // tab
    97         dt.functions[10]   = FaslReader.FASL_SHARP_ILLEGAL; // newline, linefeed
    98         dt.functions[12]   = FaslReader.FASL_SHARP_ILLEGAL; // page
    99         dt.functions[13]   = FaslReader.FASL_SHARP_ILLEGAL; // return
    100         dispatchTables['#'] = dt;
     79        LispObject[] dtfunctions = dt.functions.constants;
     80        dtfunctions['(']  = FaslReader.FASL_SHARP_LEFT_PAREN;
     81        dtfunctions['*']  = FaslReader.FASL_SHARP_STAR;
     82        dtfunctions['.']  = FaslReader.FASL_SHARP_DOT;
     83        dtfunctions[':']  = FaslReader.FASL_SHARP_COLON;
     84        dtfunctions['A']  = FaslReader.FASL_SHARP_A;
     85        dtfunctions['B']  = FaslReader.FASL_SHARP_B;
     86        dtfunctions['C']  = FaslReader.FASL_SHARP_C;
     87        dtfunctions['O']  = FaslReader.FASL_SHARP_O;
     88        dtfunctions['P']  = FaslReader.FASL_SHARP_P;
     89        dtfunctions['R']  = FaslReader.FASL_SHARP_R;
     90        dtfunctions['S']  = FaslReader.FASL_SHARP_S;
     91        dtfunctions['X']  = FaslReader.FASL_SHARP_X;
     92        dtfunctions['\''] = FaslReader.FASL_SHARP_QUOTE;
     93        dtfunctions['\\'] = FaslReader.FASL_SHARP_BACKSLASH;
     94        dtfunctions['|']  = FaslReader.FASL_SHARP_VERTICAL_BAR;
     95        dtfunctions[')']  = FaslReader.FASL_SHARP_ILLEGAL;
     96        dtfunctions['<']  = FaslReader.FASL_SHARP_ILLEGAL;
     97        dtfunctions[' ']  = FaslReader.FASL_SHARP_ILLEGAL;
     98        dtfunctions[8]    = FaslReader.FASL_SHARP_ILLEGAL; // backspace
     99        dtfunctions[9]    = FaslReader.FASL_SHARP_ILLEGAL; // tab
     100        dtfunctions[10]   = FaslReader.FASL_SHARP_ILLEGAL; // newline, linefeed
     101        dtfunctions[12]   = FaslReader.FASL_SHARP_ILLEGAL; // page
     102        dtfunctions[13]   = FaslReader.FASL_SHARP_ILLEGAL; // return
     103        dispatchTables.constants['#'] = dt;
    101104
    102105        readtableCase = Keyword.UPCASE;
  • trunk/abcl/src/org/armedbear/lisp/LispCharacter.java

    r12148 r12192  
    3838public final class LispCharacter extends LispObject
    3939{
    40   public static final LispCharacter[] constants = new LispCharacter[CHAR_MAX];
     40  public static final LispCharacter[] constants;
     41  public static final CharHashMap<LispCharacter> lispChars;
    4142
    4243  static
    4344  {
     45    lispChars = new CharHashMap<LispCharacter>(LispCharacter.class,null){
     46      public LispCharacter get(char c) {
     47        LispCharacter lc = super.get(c);
     48        if (lc==null) {
     49          lc = new LispCharacter(c);
     50          put(c, lc);
     51        }
     52        return lc;
     53      }
     54    };
     55    constants = lispChars.constants;
    4456    for (int i = constants.length; i-- > 0;)
    4557      constants[i] = new LispCharacter((char)i);
     
    5264    try
    5365      {
    54         return constants[c];
     66        return lispChars.get(c);
    5567      }
    5668    catch (ArrayIndexOutOfBoundsException e)
     
    342354          int n = Fixnum.getValue(arg);
    343355          if (n < CHAR_MAX)
    344             return constants[n];
     356            return lispChars.get((char)n);
    345357          else if (n <= Character.MAX_VALUE)
    346358            return new LispCharacter((char)n);
     
    614626      }
    615627    if (c<0 || c>255) return null;
    616     return constants[c].name;
     628    return lispChars.get(c).name;
    617629  }
    618630
     
    652664 
    653665  static void setCharName(int settingChar, String string) {
    654     if (settingChar>=CHAR_MAX) return;
    655     LispCharacter c = constants[settingChar];
     666    LispCharacter c = lispChars.get((char)settingChar);
    656667    c.name = string;
    657668    namedToChar.put(string.toLowerCase(), c);
  • trunk/abcl/src/org/armedbear/lisp/Readtable.java

    r12162 r12192  
    3333
    3434package org.armedbear.lisp;
     35import java.util.Iterator;
    3536
    3637public class Readtable extends LispObject
     
    4344  public static final byte SYNTAX_TYPE_MULTIPLE_ESCAPE       = 5;
    4445
    45   protected final byte[]          syntax               = new byte[CHAR_MAX];
    46   protected final LispObject[]    readerMacroFunctions = new LispObject[CHAR_MAX];
    47   protected final DispatchTable[] dispatchTables       = new DispatchTable[CHAR_MAX];
     46  protected final CharHashMap<Byte> syntax = new CharHashMap<Byte>(Byte.class,SYNTAX_TYPE_CONSTITUENT);
     47  protected final CharHashMap<LispObject> readerMacroFunctions = new CharHashMap<LispObject>(LispObject.class,null);
     48  protected final CharHashMap<DispatchTable> dispatchTables = new CharHashMap<DispatchTable>(DispatchTable.class,null);
    4849
    4950  protected LispObject readtableCase;
     
    5657  protected void initialize()
    5758  {
     59    Byte[] syntax = this.syntax.constants;
    5860    syntax[9]    = SYNTAX_TYPE_WHITESPACE; // tab
    5961    syntax[10]   = SYNTAX_TYPE_WHITESPACE; // linefeed
     
    7577    syntax['|']  = SYNTAX_TYPE_MULTIPLE_ESCAPE;
    7678
     79    LispObject[] readerMacroFunctions = this.readerMacroFunctions.constants;
    7780    readerMacroFunctions[';']  = LispReader.READ_COMMENT;
    7881    readerMacroFunctions['"']  = LispReader.READ_STRING;
     
    8790
    8891    DispatchTable dt = new DispatchTable();
    89 
    90     dt.functions['(']  = LispReader.SHARP_LEFT_PAREN;
    91     dt.functions['*']  = LispReader.SHARP_STAR;
    92     dt.functions['.']  = LispReader.SHARP_DOT;
    93     dt.functions[':']  = LispReader.SHARP_COLON;
    94     dt.functions['A']  = LispReader.SHARP_A;
    95     dt.functions['B']  = LispReader.SHARP_B;
    96     dt.functions['C']  = LispReader.SHARP_C;
    97     dt.functions['O']  = LispReader.SHARP_O;
    98     dt.functions['P']  = LispReader.SHARP_P;
    99     dt.functions['R']  = LispReader.SHARP_R;
    100     dt.functions['S']  = LispReader.SHARP_S;
    101     dt.functions['X']  = LispReader.SHARP_X;
    102     dt.functions['\''] = LispReader.SHARP_QUOTE;
    103     dt.functions['\\'] = LispReader.SHARP_BACKSLASH;
    104     dt.functions['|']  = LispReader.SHARP_VERTICAL_BAR;
    105     dt.functions[')']  = LispReader.SHARP_ILLEGAL;
    106     dt.functions['<']  = LispReader.SHARP_ILLEGAL;
    107     dt.functions[' ']  = LispReader.SHARP_ILLEGAL;
    108     dt.functions[8]    = LispReader.SHARP_ILLEGAL; // backspace
    109     dt.functions[9]    = LispReader.SHARP_ILLEGAL; // tab
    110     dt.functions[10]   = LispReader.SHARP_ILLEGAL; // newline, linefeed
    111     dt.functions[12]   = LispReader.SHARP_ILLEGAL; // page
    112     dt.functions[13]   = LispReader.SHARP_ILLEGAL; // return
    113 
    114     dispatchTables['#'] = dt;
     92    LispObject[] dtfunctions = dt.functions.constants;
     93    dtfunctions['(']  = LispReader.SHARP_LEFT_PAREN;
     94    dtfunctions['*']  = LispReader.SHARP_STAR;
     95    dtfunctions['.']  = LispReader.SHARP_DOT;
     96    dtfunctions[':']  = LispReader.SHARP_COLON;
     97    dtfunctions['A']  = LispReader.SHARP_A;
     98    dtfunctions['B']  = LispReader.SHARP_B;
     99    dtfunctions['C']  = LispReader.SHARP_C;
     100    dtfunctions['O']  = LispReader.SHARP_O;
     101    dtfunctions['P']  = LispReader.SHARP_P;
     102    dtfunctions['R']  = LispReader.SHARP_R;
     103    dtfunctions['S']  = LispReader.SHARP_S;
     104    dtfunctions['X']  = LispReader.SHARP_X;
     105    dtfunctions['\''] = LispReader.SHARP_QUOTE;
     106    dtfunctions['\\'] = LispReader.SHARP_BACKSLASH;
     107    dtfunctions['|']  = LispReader.SHARP_VERTICAL_BAR;
     108    dtfunctions[')']  = LispReader.SHARP_ILLEGAL;
     109    dtfunctions['<']  = LispReader.SHARP_ILLEGAL;
     110    dtfunctions[' ']  = LispReader.SHARP_ILLEGAL;
     111    dtfunctions[8]    = LispReader.SHARP_ILLEGAL; // backspace
     112    dtfunctions[9]    = LispReader.SHARP_ILLEGAL; // tab
     113    dtfunctions[10]   = LispReader.SHARP_ILLEGAL; // newline, linefeed
     114    dtfunctions[12]   = LispReader.SHARP_ILLEGAL; // page
     115    dtfunctions[13]   = LispReader.SHARP_ILLEGAL; // return
     116
     117    dispatchTables.constants['#'] = dt;
    115118
    116119    readtableCase = Keyword.UPCASE;
     
    126129    synchronized (rt)
    127130      {
    128         System.arraycopy(rt.syntax, 0, syntax, 0, CHAR_MAX);
    129         System.arraycopy(rt.readerMacroFunctions, 0, readerMacroFunctions, 0,
    130                          CHAR_MAX);
    131         // Deep copy.
    132         for (int i = dispatchTables.length; i-- > 0;)
    133           {
    134             DispatchTable dt = rt.dispatchTables[i];
    135             if (dt != null)
    136               dispatchTables[i] = new DispatchTable(dt);
    137           }
    138         readtableCase = rt.readtableCase;
     131        copyReadtable(rt, this);
    139132      }
    140133  }
     
    143136  private static void copyReadtable(Readtable from, Readtable to)
    144137  {
    145     System.arraycopy(from.syntax, 0, to.syntax, 0, CHAR_MAX);
    146     System.arraycopy(from.readerMacroFunctions, 0, to.readerMacroFunctions, 0,
    147                      CHAR_MAX);
    148     for (int i = from.dispatchTables.length; i-- > 0;)
    149       {
    150         DispatchTable dt = from.dispatchTables[i];
    151         if (dt != null)
    152           to.dispatchTables[i] = new DispatchTable(dt);
    153         else
    154           to.dispatchTables[i] = null;
    155       }
    156     to.readtableCase = from.readtableCase;
     138    Iterator<Character> charIterator = from.syntax.getCharIterator();
     139      while (charIterator.hasNext()) {
     140        char c = charIterator.next();
     141          Byte dt = from.syntax.get(c);
     142          if (dt!=null) {
     143              to.syntax.put(c, dt);         
     144          } else {
     145              to.syntax.put(c, null);         
     146          }     
     147      }     
     148      charIterator = from.readerMacroFunctions.getCharIterator();
     149      while (charIterator.hasNext()) {
     150        char c = charIterator.next();
     151          LispObject dt = from.readerMacroFunctions.get(c);
     152          if (dt!=null) {
     153              to.readerMacroFunctions.put(c, dt);         
     154          } else {
     155              to.readerMacroFunctions.put(c, null);         
     156          }     
     157      }
     158      charIterator = from.dispatchTables.getCharIterator();
     159      while (charIterator.hasNext()) {
     160        char c = charIterator.next();
     161          DispatchTable dt = from.dispatchTables.get(c);
     162          if (dt!=null) {
     163              to.dispatchTables.put(c, new DispatchTable(dt));         
     164          } else {
     165              to.dispatchTables.put(c, null);         
     166          }     
     167      }
     168      to.readtableCase = from.readtableCase;
    157169  }
    158170
     
    192204  public boolean isWhitespace(char c)
    193205  {
    194     if (c < CHAR_MAX)
    195       return syntax[c] == SYNTAX_TYPE_WHITESPACE;
    196     return false;
     206    return getSyntaxType(c) == SYNTAX_TYPE_WHITESPACE;
    197207  }
    198208
    199209  public byte getSyntaxType(char c)
    200210  {
    201     if (c < CHAR_MAX)
    202       return syntax[c];
    203     return SYNTAX_TYPE_CONSTITUENT;
     211    return syntax.get(c);
    204212  }
    205213
     
    240248  public LispObject getReaderMacroFunction(char c)
    241249  {
    242     if (c < CHAR_MAX)
    243       return readerMacroFunctions[c];
    244     else
    245       return null;
     250    return readerMacroFunctions.get(c);
    246251  }
    247252
     
    252257    if (function != null)
    253258      {
    254         if (syntax[c] == SYNTAX_TYPE_NON_TERMINATING_MACRO)
     259        if (syntax.get(c) == SYNTAX_TYPE_NON_TERMINATING_MACRO)
    255260          non_terminating_p = T;
    256261        else
     
    273278      syntaxType = SYNTAX_TYPE_TERMINATING_MACRO;
    274279    // FIXME synchronization
    275     syntax[dispChar] = syntaxType;
    276     readerMacroFunctions[dispChar] = LispReader.READ_DISPATCH_CHAR;
    277     dispatchTables[dispChar] = new DispatchTable();
     280    syntax.put(dispChar,syntaxType);
     281    readerMacroFunctions.put(dispChar, LispReader.READ_DISPATCH_CHAR);
     282    dispatchTables.put(dispChar, new DispatchTable());
    278283  }
    279284
     
    281286    throws ConditionThrowable
    282287  {
    283     DispatchTable dispatchTable = dispatchTables[dispChar];
     288    DispatchTable dispatchTable = dispatchTables.get(dispChar);
    284289    if (dispatchTable == null)
    285290      {
     
    289294      }
    290295    LispObject function =
    291       dispatchTable.functions[LispCharacter.toUpperCase(subChar)];
     296      dispatchTable.functions.get(LispCharacter.toUpperCase(subChar));
    292297    return (function != null) ? function : NIL;
    293298  }
     
    297302    throws ConditionThrowable
    298303  {
    299     DispatchTable dispatchTable = dispatchTables[dispChar];
     304    DispatchTable dispatchTable = dispatchTables.get(dispChar);
    300305    if (dispatchTable == null)
    301306      {
     
    304309                             " is not a dispatch character."));
    305310      }
    306     dispatchTable.functions[LispCharacter.toUpperCase(subChar)] = function;
     311    dispatchTable.functions.put(LispCharacter.toUpperCase(subChar), function);
    307312  }
    308313
    309314  protected static class DispatchTable
    310315  {
    311     public LispObject[] functions = new LispObject[CHAR_MAX];
     316  protected final CharHashMap<LispObject> functions;
    312317
    313318    public DispatchTable()
    314319    {
     320      functions = new CharHashMap<LispObject>(LispObject.class,null);
    315321    }
    316322
    317323    public DispatchTable(DispatchTable dt)
    318324    {
    319       for (int i = 0; i < functions.length; i++)
    320         functions[i] = dt.functions[i];
     325      functions = (CharHashMap<LispObject>) dt.functions.clone();
    321326    }
    322327  }
     
    428433        Readtable rt = designator_readtable(fourth);
    429434        // REVIEW synchronization
    430         rt.syntax[c] = syntaxType;
    431         rt.readerMacroFunctions[c] = designator;
     435        rt.syntax.put(c, syntaxType);
     436        rt.readerMacroFunctions.put(c, designator);
    432437        return T;
    433438      }
     
    531536          fromReadtable = checkReadtable(STANDARD_READTABLE.symbolValue());
    532537        // REVIEW synchronization
    533         toReadtable.syntax[toChar] = fromReadtable.syntax[fromChar];
    534         toReadtable.readerMacroFunctions[toChar] =
    535           fromReadtable.readerMacroFunctions[fromChar];
     538        toReadtable.syntax.put(toChar, fromReadtable.syntax.get(fromChar));
     539        toReadtable.readerMacroFunctions.put(toChar,
     540            fromReadtable.readerMacroFunctions.get(fromChar));
    536541        // "If the character is a dispatching macro character, its entire
    537542        // dispatch table of reader macro functions is copied."
    538         if (fromReadtable.dispatchTables[fromChar] != null)
    539           {
    540             toReadtable.dispatchTables[toChar] =
    541               new DispatchTable(fromReadtable.dispatchTables[fromChar]);
    542           }
     543        DispatchTable found = fromReadtable.dispatchTables.get(fromChar);
     544        if (found!=null)
     545          toReadtable.dispatchTables.put(toChar, new DispatchTable(found));         
    543546        else
    544547            // Don't leave behind dispatch tables when fromChar
    545548            // doesn't have one
    546             toReadtable.dispatchTables[toChar] = null;
     549          toReadtable.dispatchTables.put(toChar, null);
    547550        return T;
    548551      }
Note: See TracChangeset for help on using the changeset viewer.