1 | static final HashMap<S, Method[]> callMC_cache = new HashMap; |
2 | static S callMC_key; |
3 | static Method callMC_value; |
4 | |
5 | // varargs assignment fixer for a single string array argument |
6 | static Object callMC(S method, S[] arg) { |
7 | ret callMC(method, new O[] {arg}); |
8 | } |
9 | |
10 | static O callMC(S method, O... args) ctex { |
11 | Method me; |
12 | synchronized(callMC_cache) { |
13 | me = method == callMC_key ? callMC_value : null; |
14 | } |
15 | if (me != null) ret callMC_value.invoke(null, args); |
16 | |
17 | Method[] m; |
18 | synchronized(callMC_cache) { |
19 | m = callMC_cache.get(method); |
20 | } |
21 | if (m == null) { |
22 | if (callMC_cache.isEmpty()) { |
23 | callMC_makeCache(); |
24 | m = callMC_cache.get(method); |
25 | } |
26 | if (m == null) fail("Method named " + method + " not found in main"); |
27 | } |
28 | int n = m.length; |
29 | if (n == 1) { |
30 | me = m[0]; |
31 | synchronized(callMC_cache) { |
32 | callMC_key = method; |
33 | callMC_value = me; |
34 | } |
35 | ret me.invoke(null, args); |
36 | } |
37 | for i to n: { |
38 | me = m[i]; |
39 | if (call_checkArgs(me, args, false)) |
40 | ret me.invoke(null, args); |
41 | } |
42 | fail("No method called " + method + " with matching arguments found in main"); |
43 | } |
44 | |
45 | static void callMC_makeCache() { |
46 | synchronized(callMC_cache) { |
47 | callMC_cache.clear(); |
48 | Class _c = (Class) mc(), c = _c; |
49 | while (c != null) { |
50 | for (Method m : c.getDeclaredMethods()) |
51 | if ((m.getModifiers() & Modifier.STATIC) != 0 |
52 | && !reflection_isForbiddenMethod(m)) { |
53 | m.setAccessible(true); |
54 | multiMapPut_array(callMC_cache, m.getName(), m); |
55 | } |
56 | c = c.getSuperclass(); |
57 | } |
58 | } |
59 | } |
Began life as a copy of #1005370
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1011182 |
Snippet name: | callMC - call function in main class, optimizing [dev.] |
Eternal ID of this version: | #1011182/2 |
Text MD5: | 54307baabad9c43616171845a06decb0 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-04-01 04:59:25 |
Source code size: | 1610 bytes / 59 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 414 / 438 |
Version history: | 1 change(s) |
Referenced in: | [show references] |