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)

// calling a method with a fixed name and
// argument type on a (possibly) changing object
// as fast as possible

static Symbol symbol_bla = toSymbol("bla");

sclass CallSiteCache_oneArg {
  Class targetClass;
  Class argType; // set to null if target method is not overloaded
  MethodHandle mh;
}

static WeakReference<CallSiteCache_oneArg> callSite1_cache;

if (o != null) {
  var cache == getWeakRef(callSite1_cache);
  Class c = o.getClass();
  Class argType = _getClass(arg);
  if (cache != null && cache! == c
    && (cache.argType == null || cache.argType == argType)) {}
  else {
    cache = findCachedMethod(x, symbol_bla, arg);
    callSite1_cache = weakRef(cache);
  }
  invoke(cache.mh, arg);
}

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: 123 / 139
Referenced in: [show references]