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

26
LINES

< > BotCompany Repo | #1031624 // Calling a method with a fixed name and / argument type on a (possibly) changing object / as fast as possible

JavaX (incomplete)

1  
// calling a method with a fixed name and
2  
// argument type on a (possibly) changing object
3  
// as fast as possible
4  
5  
static Symbol symbol_bla = toSymbol("bla");
6  
7  
sclass CallSiteCache_oneArg {
8  
  Class targetClass;
9  
  Class argType; // set to null if target method is not overloaded
10  
  MethodHandle mh;
11  
}
12  
13  
static WeakReference<CallSiteCache_oneArg> callSite1_cache;
14  
15  
if (o != null) {
16  
  var cache == getWeakRef(callSite1_cache);
17  
  Class c = o.getClass();
18  
  Class argType = _getClass(arg);
19  
  if (cache != null && cache! == c
20  
    && (cache.argType == null || cache.argType == argType)) {}
21  
  else {
22  
    cache = findCachedMethod(x, symbol_bla, arg);
23  
    callSite1_cache = weakRef(cache);
24  
  }
25  
  invoke(cache.mh, arg);
26  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031624
Snippet name: Calling a method with a fixed name and / argument type on a (possibly) changing object / as fast as possible
Eternal ID of this version: #1031624/1
Text MD5: 9947cad4e194696d66ccdfc5aca84590
Author: stefan
Category:
Type: JavaX (incomplete)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-22 12:58:34
Source code size: 732 bytes / 26 lines
Pitched / IR pitched: No / No
Views / Downloads: 125 / 142
Referenced in: [show references]