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

15
LINES

< > BotCompany Repo | #1010513 // tok_cachedFunctions - use class Cache (single object cache)

JavaX fragment (include)

// now using lambda0 instead of f
static void tok_cachedFunctions(L<S> tok) { pcall {
  if (!tok.contains("cached")) ret;
  int i;
  while ((i = jfind(tok, "static cached <id>")) >= 0) {
    int bracket = indexOf(tok, "(", i);
    S fName = assertIdentifier(tok.get(bracket-2));
    S type = joinSubList(tok, i+4, bracket-3);
    S boxedType = tok_toNonPrimitiveTypes(type);
    
    replaceTokens(tok, i, bracket-1, "static Cache<\*boxedType*/> \*fName*/_cache = new Cache<>(lambda0 \*fName*/_load);\n"
      + "static \*type*/ \*fName*/() { ret \*fName*/_cache!; }\n\n" + "static \*boxedType*/ \*fName*/_load");
    reTok(tok, i, bracket-3);
  }
}}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1010513
Snippet name: tok_cachedFunctions - use class Cache (single object cache)
Eternal ID of this version: #1010513/12
Text MD5: 86ada33690f2ca5314b2c993a8234c82
Author: stefan
Category: javax / transpiling
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-08 10:19:05
Source code size: 664 bytes / 15 lines
Pitched / IR pitched: No / No
Views / Downloads: 548 / 607
Version history: 11 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1020989 - tok_simplyCachedFunctions
#1025861 - tok_timedCachedFunctions - use class TimedCache (single object cache)