1 | // stores all strings as UTF8 (typically half as big) |
2 | static class CondensedStrings2 extends AbstractList<S> implements RandomAccess { |
3 | byte[] data; |
4 | int[] indices; |
5 | |
6 | *() {} // only for serialisation |
7 | |
8 | *(L<S> l) { |
9 | long totalLength = 0; |
10 | for (S s : l) totalLength += l(toUtf8(s)); |
11 | int len = (int) totalLength; |
12 | if (len != totalLength) fail("TOO BIG!!!!!! " + totalLength); |
13 | data = new byte[len]; |
14 | int n = l(l); |
15 | indices = new int[n]; |
16 | int idx = 0; |
17 | for (int i = 0; i < n; i++) { |
18 | S s = l.get(i); |
19 | try { |
20 | byte[] x = toUtf8(s); |
21 | System.arraycopy(x, 0, data, idx, l(x)); |
22 | indices[i] = idx; |
23 | idx += l(x); |
24 | } catch (RuntimeException e) { |
25 | print("idx=" + idx + ", s=" + s + ", i=" + i +", n=" + n + ", len=" + len); |
26 | throw e; |
27 | } |
28 | } |
29 | } |
30 | |
31 | public S get(int i) ctex { |
32 | int idx1 = indices[i]; |
33 | int idx2 = i+1 < indices.length ? indices[i+1] : data.length; |
34 | ret fastu_fromUtf8(data, idx1, idx2-idx1); |
35 | } |
36 | |
37 | public int size() { |
38 | ret indices.length; |
39 | } |
40 | |
41 | int totalSize() { |
42 | ret data.length; |
43 | } |
44 | } |
Began life as a copy of #1002526
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1002528 |
Snippet name: | CondensedStrings2 (include) |
Eternal ID of this version: | #1002528/6 |
Text MD5: | ef305b78b10a4da64ec508f356e43dfa |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-10-30 02:29:30 |
Source code size: | 1150 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 701 / 1847 |
Version history: | 5 change(s) |
Referenced in: | [show references] |