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

24
LINES

< > BotCompany Repo | #1022097 // massageArgsForVarArgsCall - TODO: optimize for case where there is a single O... parameter

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (85L) is out of date.

static O[] massageArgsForVarArgsCall(Executable m, O[] args) {
  Class<?>[] types = m.getParameterTypes();
  int n = types.length-1, nArgs = l(args);
  if (nArgs < n) null;
  for i to n:
    if (!argumentCompatibleWithType(args[i], types[i]))
      null;
  Class varArgType = types[n].getComponentType();
  for (int i = n; i < nArgs; i++)
    if (!argumentCompatibleWithType(args[i], varArgType))
      null;
  O[] newArgs = new O[n+1];
  arraycopy(args, 0, newArgs, 0, n);
  
  // TODO: optimize
  
  int nVarArgs = nArgs-n;
  O varArgs = Array.newInstance(varArgType, nVarArgs);
  for i to nVarArgs:
    Array.set(varArgs, i, args[n+i]);
    
  newArgs[n] = varArgs;
  ret newArgs;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022097
Snippet name: massageArgsForVarArgsCall - TODO: optimize for case where there is a single O... parameter
Eternal ID of this version: #1022097/6
Text MD5: d607e53cf40eba7155e65e6ad89bcfa7
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-13 02:22:48
Source code size: 708 bytes / 24 lines
Pitched / IR pitched: No / No
Views / Downloads: 370 / 490
Version history: 5 change(s)
Referenced in: [show references]