| 16 | // |
| 17 | // Called by RE2.doExecute. |
| 18 | class Machine { |
| 19 | |
| 20 | // A logical thread in the NFA. |
| 21 | private static class Thread { |
| 22 | Thread(int n) { |
| 23 | this.cap = new int[n]; |
| 24 | } |
| 25 | |
| 26 | int[] cap; |
| 27 | Inst inst; |
| 28 | } |
| 29 | |
| 30 | // A queue is a 'sparse array' holding pending threads of execution. See: |
| 31 | // research.swtch.com/2008/03/using-uninitialized-memory-for-fun-and.html |
| 32 | private static class Queue { |
| 33 | |
| 34 | final Thread[] denseThreads; // may contain stale Thread in slots >= size |
| 35 | final int[] densePcs; // may contain stale pc in slots >= size |
| 36 | final int[] sparse; // may contain stale but in-bounds values. |
| 37 | int size; // of prefix of |dense| that is logically populated |
| 38 | |
| 39 | Queue(int n) { |
| 40 | this.sparse = new int[n]; |
| 41 | this.densePcs = new int[n]; |
| 42 | this.denseThreads = new Thread[n]; |
| 43 | } |
| 44 | |
| 45 | boolean contains(int pc) { |
| 46 | int j = sparse[pc]; |
| 47 | return j < size && densePcs[j] == pc; |
| 48 | } |
| 49 | |
| 50 | boolean isEmpty() { |
| 51 | return size == 0; |
| 52 | } |
| 53 | |
| 54 | int add(int pc) { |
| 55 | int j = size++; |
| 56 | sparse[pc] = j; |
| 57 | denseThreads[j] = null; |
| 58 | densePcs[j] = pc; |
| 59 | return j; |
| 60 | } |
| 61 | |
| 62 | void clear() { |
| 63 | size = 0; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public String toString() { |
| 68 | StringBuilder out = new StringBuilder(); |
| 69 | out.append('{'); |
| 70 | for (int i = 0; i < size; ++i) { |
| 71 | if (i != 0) { |
| 72 | out.append(", "); |
| 73 | } |
| 74 | out.append(densePcs[i]); |
| 75 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…