Changeset 10369


Ignore:
Timestamp:
11/05/05 19:16:01 (16 years ago)
Author:
piso
Message:

Use a hash table for getSlotIndex().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/Layout.java

    r10360 r10369  
    33 *
    44 * Copyright (C) 2003-2005 Peter Graves
    5  * $Id: Layout.java,v 1.21 2005-11-05 01:20:21 piso Exp $
     5 * $Id: Layout.java,v 1.22 2005-11-05 19:16:01 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    3030    private final LispObject sharedSlots;
    3131
     32    private static final boolean useHashTable = true;
     33
     34    private final EqHashTable ht;
     35
    3236    public Layout(LispClass cls, LispObject instanceSlots, LispObject sharedSlots)
    3337    {
     
    5660        Debug.assertTrue(i == length);
    5761        this.sharedSlots = sharedSlots;
     62
     63        if (useHashTable) {
     64            ht = new EqHashTable(slotNames.length, NIL, NIL);
     65            for (i = slotNames.length; i-- > 0;)
     66                ht.put(slotNames[i], new Fixnum(i));
     67        } else
     68            ht = null;
    5869    }
    5970
     
    6475        this.slotNames = instanceSlotNames;
    6576        this.sharedSlots = sharedSlots;
     77
     78        if (useHashTable) {
     79            ht = new EqHashTable(slotNames.length, NIL, NIL);
     80            for (int i = slotNames.length; i-- > 0;)
     81                ht.put(slotNames[i], new Fixnum(i));
     82        } else
     83            ht = null;
    6684    }
    6785
     
    7290        slotNames = oldLayout.slotNames;
    7391        sharedSlots = oldLayout.sharedSlots;
     92
     93        if (useHashTable) {
     94            ht = new EqHashTable(slotNames.length, NIL, NIL);
     95            for (int i = slotNames.length; i-- > 0;)
     96                ht.put(slotNames[i], new Fixnum(i));
     97        } else
     98            ht = null;
    7499    }
    75100
     
    187212    public int getSlotIndex(LispObject slotName)
    188213    {
     214        if (useHashTable) {
     215            LispObject index = ht.get(slotName);
     216            if (index != null)
     217                return ((Fixnum)index).value;
     218            return -1;
     219        }
    189220        for (int i = slotNames.length; i-- > 0;) {
    190221            if (slotNames[i] == slotName)
Note: See TracChangeset for help on using the changeset viewer.