1 28 package org.jruby.runtime; 29 30 import java.util.WeakHashMap ; 31 import java.util.Iterator ; 32 import java.util.Map ; 33 import org.jruby.Ruby; 34 35 import org.jruby.RubyModule; 36 import org.jruby.internal.runtime.methods.DynamicMethod; 37 import org.jruby.util.WeakIdentityHashMap; 38 39 54 public class CacheMap { 55 private final Map mappings = new WeakHashMap (); 56 private final Ruby runtime; 57 58 public CacheMap(Ruby runtime) { 59 this.runtime = runtime; 60 } 61 62 68 public void add(DynamicMethod method, RubyModule module) { 69 Map classList = (Map ) mappings.get(method); 70 71 if (classList == null) { 72 classList = new WeakIdentityHashMap(); 73 mappings.put(method, classList); 74 } 75 76 classList.put(module,null); 77 } 78 79 87 public void remove(String name, DynamicMethod method) { 88 Map classList = (Map ) mappings.remove(method); 89 90 if (classList == null) { 92 return; 93 } 94 95 for(Iterator iter = classList.keySet().iterator(); iter.hasNext();) { 96 RubyModule module = (RubyModule) iter.next(); 97 if (module != null) { 98 module.removeCachedMethod(name); 99 100 if (module.index != 0) { 101 runtime.getSelectorTable().table[module.index][MethodIndex.getIndex(name)] = 0; 102 } 103 } 104 } 105 } 106 } 107 | Popular Tags |