|
1 | 1 | package com.lexicalscope.svm.partition.trace;
|
2 | 2 |
|
3 | 3 | import static com.lexicalscope.svm.partition.trace.Trace.CallReturn.CALL;
|
4 |
| -import static java.util.Arrays.copyOf; |
5 | 4 |
|
6 | 5 | import java.util.Arrays;
|
7 | 6 | import java.util.HashMap;
|
@@ -44,38 +43,16 @@ private Trace(
|
44 | 43 | }
|
45 | 44 |
|
46 | 45 | public Trace extend(final SMethodDescriptor methodCalled, final CallReturn callReturn, final Object ... args) {
|
47 |
| - final Object[] normalisedArgs = copyOf(args, args.length); |
48 |
| - int newNextAlias = nextAlias; |
49 |
| - Map<Object, Alias> newMap = map; |
50 |
| - |
51 |
| - if(callReturn.equals(CallReturn.CALL)) { |
52 |
| - for (final int i : methodCalled.objectArgIndexes()) { |
53 |
| - Alias alias; |
54 |
| - if(null == (alias = newMap.get(args[i + 1]))) { |
55 |
| - // TODO[tim] do COW here |
56 |
| - if(map == newMap) { |
57 |
| - newMap = new HashMap<>(map); |
58 |
| - } |
59 |
| - alias = new Alias(newNextAlias++); |
60 |
| - newMap.put(args[i + 1], alias); |
61 |
| - } |
62 |
| - normalisedArgs[i + 1] = alias; |
63 |
| - } |
| 46 | + final TraceExtender traceExtender = new TraceExtender(args, map, nextAlias); |
| 47 | + |
| 48 | + if(callReturn.equals(CALL)) { |
| 49 | + traceExtender.aliasesForCallArguments(methodCalled.objectArgIndexes()); |
64 | 50 | }
|
65 |
| - if(callReturn.equals(CallReturn.CALL) || methodCalled.returnIsObject()) { |
66 |
| - Alias alias; |
67 |
| - if(null == (alias = newMap.get(args[0]))) { |
68 |
| - // TODO[tim] do COW here |
69 |
| - if(map == newMap) { |
70 |
| - newMap = new HashMap<>(map); |
71 |
| - } |
72 |
| - alias = new Alias(newNextAlias++); |
73 |
| - newMap.put(args[0], alias); |
74 |
| - } |
75 |
| - normalisedArgs[0] = alias; |
| 51 | + if(callReturn.equals(CALL) || methodCalled.returnIsObject()) { |
| 52 | + traceExtender.aliasesForZerothArguments(); |
76 | 53 | }
|
77 | 54 |
|
78 |
| - return new Trace(this, newMap, newNextAlias, methodCalled, callReturn, normalisedArgs); |
| 55 | + return new Trace(this, traceExtender.newMap(), traceExtender.newNextAlias(), methodCalled, callReturn, traceExtender.normalisedArgs()); |
79 | 56 | }
|
80 | 57 |
|
81 | 58 | public List<Trace> asList() {
|
|
0 commit comments