Libraryless. Click here for Pure Java version (2144L/14K).
1 | static Map<Class, HashMap<S, Method>> callOpt_noArgs_cache = newDangerousWeakHashMap(); |
2 | |
3 | static O callOpt_noArgs(O o, S method) ctex { |
4 | if (o == null) ret null; |
5 | if (o instanceof Class) |
6 | ret callOpt(o, method); // not optimized |
7 | |
8 | Class c = o.getClass(); |
9 | HashMap<S, Method> map; |
10 | synchronized(callOpt_noArgs_cache) { |
11 | map = callOpt_noArgs_cache.get(c); |
12 | if (map == null) |
13 | map = callOpt_noArgs_makeCache(c); |
14 | } |
15 | |
16 | Method m = map.get(method); |
17 | ret m != null ? m.invoke(o) : null; |
18 | } |
19 | |
20 | // used internally - we are in synchronized block |
21 | static HashMap<S, Method> callOpt_noArgs_makeCache(Class c) { |
22 | new HashMap<S, Method> map; |
23 | Class _c = c; |
24 | do { |
25 | for (Method m : c.getDeclaredMethods()) |
26 | if (m.getParameterTypes().length == 0 |
27 | && !reflection_isForbiddenMethod(m)) { |
28 | makeAccessible(m); |
29 | S name = m.getName(); |
30 | if (!map.containsKey(name)) |
31 | map.put(name, m); |
32 | } |
33 | _c = _c.getSuperclass(); |
34 | } while (_c != null); |
35 | callOpt_noArgs_cache.put(c, map); |
36 | ret map; |
37 | } |
Began life as a copy of #1001199
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1005607 |
Snippet name: | callOpt_noArgs - optimized version of callOpt when you don't pass arguments |
Eternal ID of this version: | #1005607/5 |
Text MD5: | ac9de21476b927ab4ec9cc04e381721d |
Transpilation MD5: | a8c84bb572f1bd8ab6c67db467263145 |
Author: | stefan |
Category: | |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-08-31 14:51:15 |
Source code size: | 1071 bytes / 37 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 518 / 582 |
Version history: | 4 change(s) |
Referenced in: | [show references] |