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)

please include function callOpt_cached.

static O call_cached(O o, S method, O... args) ctex {
  if (o == null) null;
  
  if (o instanceof Class) {
    Class c = (Class) o;
    _MethodCache cache = callOpt_getCache(c);
    
    // TODO: (super-rare) case where method exists static and non-static
    // with different args
    
    Method me = cache.findMethod(method, args);
    if (me == null)
      fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not found");
    if ((me.getModifiers() & Modifier.STATIC) == 0)
      fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not static");
    ret invokeMethod(me, null, args);
  } else {
    Class c = o.getClass();
    _MethodCache cache = callOpt_getCache(c);

    Method me = cache.findMethod(method, args);
    if (me == null)
      fail("Method " + c.getName() + "." + method + "(" + joinWithComma(classNames(args)) + ") not found");
    ret invokeMethod(me, o, args);
  }
}

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: 407 / 416
Version history: 2 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1022095 - call_withVarargs