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

56
LINES

< > BotCompany Repo | #1007946 - loadFunctions_cached

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

Libraryless. Click here for Pure Java version (10184L/74K).

static HashMap<Set<S>, Class> loadFunctions_cache = new HashMap;
static Lock loadFunctions_cached_lock = lock();

sbool loadFunctions_preferDiskCache; // Note: This may use outdated versions of standard functions

static Class loadFunctions_cached(S... functions) {
  ret loadFunctions_cached(asList(functions));
}

static Class loadFunctions_cached(Collection<S> functions) {
  TreeSet<S> functionSet = new TreeSet<S>(functions);
  lock loadFunctions_cached_lock;
  Class c = loadFunctions_cache.get(functionSet);
  if (c != null) ret c;
  S transpilation = null;
  
  // new mode for slow machines (Raspberry Pi): get server transpilation
  if (l(functions) == 1 && isSlowMachine()) {
    S snippetID = stdFunctions_cached().get(first(functions));
    if (nempty(snippetID)) {
      if (!isMD5(getUpToDateSnippetTranspilationMD5(snippetID)))
        print("Slow machine mode: " + snippetID + " transpilation not up to date");
      else {
        transpilation = getServerTranspiledWithoutLibs(snippetID); // TODO: libs?
        print("Loaded server transpilation: " + snippetID);
      }
    }
  }
  
  if (transpilation == null) {
    S cached = getTranspiledStandardFunctionsIfCached(functionSet);
    // TODO: make sure we're using an up-to-date transpiler too
    if (cached != null && (loadFunctions_preferDiskCache || standardFunctionsCacheUpToDate(functionSet)))
      transpilation = cached;
  }
  if (transpilation != null) {
    // TODO: LIBS
    print("Loading " + joinWithPlus(functionSet));
    c = veryQuickJava_finish(transpilation, emptyList());
  }
  
  if (c == null) c = loadFunctions(functionSet);
  
  loadFunctions_cache.put(functionSet, c);
  assertNotNull(loadFunctions_cache.get(functionSet));
  ret c;
}

svoid loadFunctions_cached_clearCache() {
  lock loadFunctions_cached_lock;
  loadFunctions_cache.clear();
}

svoid _onLoad_loadFunctions_cached {
  ownResource(vmBus_onMessage('refreshedTranspiler, r loadFunctions_clearCache));
}

Author comment

Began life as a copy of #1007852

download  show line numbers  debug dex   

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

No comments. add comment

Snippet ID: #1007946
Snippet name: loadFunctions_cached
Eternal ID of this version: #1007946/25
Text MD5: a0820ecc7bdc2bc726ee8bda851ee863
Transpilation MD5: 61b70f145fddc77d6262ab1d6219a823
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-02-12 19:44:57
Source code size: 2019 bytes / 56 lines
Pitched / IR pitched: No / No
Views / Downloads: 434 / 465
Version history: 24 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1007946 & http://1007946.tinybrain.de