Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

57
LINES

< > BotCompany Repo | #1007835 // callMC_3 - call function in main class, optimizing even more

JavaX fragment (include)

1  
static final HashMap<S, L<Method>> callMC_3_cache = new HashMap;
2  
static callMC_3_Q callMC_3_quick;
3  
4  
sclass callMC_3_Q {
5  
  S name;
6  
  Method method;
7  
}
8  
9  
// varargs assignment fixer for a single string array argument
10  
static Object callMC_3(S method, S[] arg) {
11  
  ret callMC_3(method, new O[] {arg});
12  
}
13  
14  
static O callMC_3(S method, O... args) ctex {
15  
  callMC_3_Q q = callMC_3_quick;
16  
  if (q != null && q.name == method)
17  
    ret q.method.invoke(null, args);
18  
19  
  L<Method> m = callMC_3_cache.get(method);
20  
  if (m == null) {
21  
    if (callMC_3_cache.isEmpty()) {
22  
      callMC_3_makeCache();
23  
      m = callMC_3_cache.get(method);
24  
    }
25  
    if (m == null) fail("Method named " + method + " not found in main");
26  
  }
27  
  int n = m.size();
28  
  if (n == 1) {
29  
    Method me = m.get(0);
30  
    if (q == null || q.name != method) {
31  
      q = new callMC_3_Q;
32  
      q.name = method;
33  
      q.method = me;
34  
      callMC_3_quick = q;
35  
    }
36  
    ret me.invoke(null, args);
37  
  }
38  
  for i to n: {
39  
    Method me = m.get(i);
40  
    if (call_checkArgs(me, args, false))
41  
      ret me.invoke(null, args);
42  
  }
43  
  fail("No method called " + method + " with matching arguments found in main");
44  
}
45  
46  
static synchronized void callMC_3_makeCache() {
47  
  callMC_3_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  
        m.setAccessible(true);
53  
        multiMapPut(callMC_3_cache, m.getName(), m);
54  
      }
55  
    c = c.getSuperclass();
56  
  }
57  
}

Author comment

Began life as a copy of #1007834

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: #1007835
Snippet name: callMC_3 - call function in main class, optimizing even more
Eternal ID of this version: #1007835/3
Text MD5: 9122cd20fe03bd1b15a8c4a7cf899297
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-04-11 14:39:08
Source code size: 1556 bytes / 57 lines
Pitched / IR pitched: No / No
Views / Downloads: 369 / 390
Version history: 2 change(s)
Referenced in: [show references]