Uses 911K of libraries. Click here for Pure Java version (8424L/47K).
1 | !7 |
2 | |
3 | sclass Entry { |
4 | S code, hints; |
5 | transient F1<S, O> function; |
6 | transient Throwable error; |
7 | transient Map<S, O> cache = syncMRUCache(1000); |
8 | } |
9 | |
10 | set flag DynModule. |
11 | |
12 | cmodule FunctionsOnStrings > DynObjectTable<Entry> { |
13 | transient ReliableSingleThread rstUpdateListLater = dm_rstWithDelay(this, r fireDataChanged, 10.0); |
14 | |
15 | start { |
16 | itemToMap = func(Entry e) -> Map { |
17 | litorderedmap(Code := e.code, Hints := nullIfEmpty(e.hints), |
18 | Loaded := e.function != null, |
19 | Error := strOrNull(e.error), |
20 | "Cache Size" := l(e.cache) + "/" + mruCacheSize(e.cache)) |
21 | }; |
22 | dm_vmBus_onMessage_q('refreshedTranspiler, r refresh); |
23 | } |
24 | |
25 | void refresh { |
26 | lock lock; |
27 | setData(new L); |
28 | } |
29 | |
30 | // API |
31 | |
32 | F1 getFunction(S code, S hints) { |
33 | lock lock; |
34 | Entry e = objectWhere(data(), +code, +hints); |
35 | if (e == null) add(e = nu Entry(+code, +hints)); |
36 | if (e.error != null) throw rethrow(e.error); |
37 | if (e.function == null) { |
38 | print("Loading function: " + code); |
39 | try { |
40 | final F1<S, O> f = codeWithHintsToFunctionOnString(code); |
41 | final Map<S, O> cache = e.cache; |
42 | e.function = func(S s) -> O { |
43 | if (s == null) null; |
44 | O o = cache.get(s); |
45 | if (o == null) { |
46 | cache.put(s, o = callF(f, s)); |
47 | rstUpdateListLater.trigger(); |
48 | } |
49 | ret o; |
50 | }; |
51 | fireDataChanged(); |
52 | } catch ex { |
53 | e.error = ex; |
54 | fireDataChanged(); |
55 | throw rethrow(ex); |
56 | } |
57 | } |
58 | ret e.function; |
59 | } |
60 | } |
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: | #1021247 |
Snippet name: | Functions On Strings |
Eternal ID of this version: | #1021247/17 |
Text MD5: | 9f08c0b4b4c035e5afd09307ad6179ab |
Transpilation MD5: | 7ab9b3c13bfb705531c40bf12b0dafa8 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-02-17 19:14:28 |
Source code size: | 1596 bytes / 60 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 326 / 6867 |
Version history: | 16 change(s) |
Referenced in: | [show references] |