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

28
LINES

< > BotCompany Repo | #1018503 // call_cached (optimized version of call)

JavaX fragment (include)

1  
please include function callOpt_cached.
2  
3  
static O call_cached(O o, S method, O... args) ctex {
4  
  if (o == null) null;
5  
  
6  
  if (o instanceof Class) {
7  
    Class c = (Class) o;
8  
    _MethodCache cache = callOpt_getCache(c);
9  
    
10  
    // TODO: (super-rare) case where method exists static and non-static
11  
    // with different args
12  
    
13  
    Method me = cache.findMethod(method, args);
14  
    if (me == null)
15  
      fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not found");
16  
    if ((me.getModifiers() & Modifier.STATIC) == 0)
17  
      fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not static");
18  
    ret invokeMethod(me, null, args);
19  
  } else {
20  
    Class c = o.getClass();
21  
    _MethodCache cache = callOpt_getCache(c);
22  
23  
    Method me = cache.findMethod(method, args);
24  
    if (me == null)
25  
      fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not found");
26  
    ret invokeMethod(me, o, args);
27  
  }
28  
}

Author comment

Began life as a copy of #1018497

download  show line numbers  debug dex  old transpilations   

Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1018503
Snippet name: call_cached (optimized version of call)
Eternal ID of this version: #1018503/3
Text MD5: 15f2672658a4de53e8d1aa3b58a82f8f
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-02 12:31:57
Source code size: 1034 bytes / 28 lines
Pitched / IR pitched: No / No
Views / Downloads: 406 / 416
Version history: 2 change(s)
Referenced in: [show references]