static final WeakHashMap> getOpt_cache = newWeakHashMap(); static final new HashMap getOpt_special; // just a marker static { getOpt_cache.put(Class.class, getOpt_special); getOpt_cache.put(S.class, getOpt_special); } static Object getOpt_cached(Object o, String field) ctex { if (o == null) ret null; Class c = o.getClass(); HashMap map; synchronized(getOpt_cache) { map = getOpt_cache.get(c); if (map == null) map = getOpt_makeCache(c); } if (map == getOpt_special) { if (o instanceof Class) return getOpt((Class) o, field); /*if (o instanceof S) ret getOpt(getBot((S) o), field);*/ if (o instanceof Map) ret ((Map) o).get(field); } Field f = map.get(field); if (f != null) ret f.get(o); ifclass DynamicObject if (o instanceof DynamicObject) ret ((DynamicObject) o).fieldValues.get(field); endif ret null; } // used internally - we are in synchronized block static HashMap getOpt_makeCache(Class c) { HashMap map; if (isSubtypeOf(c, Map.class)) map = getOpt_special; else { map = new HashMap; Class _c = c; do { for (Field f : _c.getDeclaredFields()) { f.setAccessible(true); S name = f.getName(); if (!map.containsKey(name)) map.put(name, f); } _c = _c.getSuperclass(); } while (_c != null); } getOpt_cache.put(c, map); ret map; }