Changeset 12957


Ignore:
Timestamp:
10/08/10 18:43:36 (13 years ago)
Author:
ehuelsmann
Message:

Use a synchronized hash table with weak keys to allow
garbage collection of the symbols in it - and of the function_info
with the symbols as soon as they disappear.

File:
1 edited

Legend:

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

    r12513 r12957  
    3434package org.armedbear.lisp;
    3535
     36import java.util.Map;
     37import java.util.Collections;
     38import java.util.WeakHashMap;
    3639import static org.armedbear.lisp.Lisp.*;
    3740
    3841public final class function_info
    3942{
    40     static EqualHashTable FUNCTION_TABLE =
    41         new EqualHashTable(64, NIL, NIL);
     43    // ### TODO: Replace by a concurrent hashmap, with weak keys, ofcourse.
     44    final static Map<LispObject,LispObject> symbolToFunctionMap =
     45        Collections.synchronizedMap(new WeakHashMap());
    4246
    4347    // ### function-info name
     
    4852        public LispObject execute(LispObject arg)
    4953        {
    50             LispObject info = FUNCTION_TABLE.get(arg);
     54            LispObject info = symbolToFunctionMap.get(arg);
    5155            return info != null ? info : NIL;
    5256        }
     
    6266        {
    6367            if (info == NIL)
    64                 FUNCTION_TABLE.remhash(name);
     68                symbolToFunctionMap.remove(name);
    6569            else
    66                 FUNCTION_TABLE.put(name, info);
     70                symbolToFunctionMap.put(name, info);
    6771            return info;
    6872        }
     
    7983        {
    8084            // info is an alist
    81             LispObject info = FUNCTION_TABLE.get(name);
     85            LispObject info = symbolToFunctionMap.get(name);
    8286            if (info != null) {
    8387                while (info != NIL) {
     
    108112        {
    109113            // info is an alist
    110             LispObject info = FUNCTION_TABLE.get(name);
     114            LispObject info = symbolToFunctionMap.get(name);
    111115            if (info == null)
    112116                info = NIL;
     
    125129            }
    126130            // Not found.
    127             FUNCTION_TABLE.put(name, info.push(new Cons(indicator, value)));
     131            symbolToFunctionMap.put(name, info.push(new Cons(indicator, value)));
    128132            return value;
    129133        }
Note: See TracChangeset for help on using the changeset viewer.