Skip to content

Commit 042e500

Browse files
committed
Extra Record type optimisation
1 parent b1749a4 commit 042e500

File tree

7 files changed

+88
-9
lines changed

7 files changed

+88
-9
lines changed

convex-benchmarks/src/main/java/convex/benchmarks/ThreadCoordinationBenchmark.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public class ThreadCoordinationBenchmark {
2121
o = INPUT.take();
2222
OUTPUT.put(o);
2323
} catch (InterruptedException e) {
24-
// TODO Auto-generated catch block
2524
e.printStackTrace();
2625
}
2726
}

convex-core/src/main/java/convex/core/data/AMap.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public final V get(Object key) {
237237
* @return Value for the specified key, or the notFound value.
238238
*/
239239
@SuppressWarnings("unchecked")
240-
public final V get(ACell key, ACell notFound) {
240+
public V get(ACell key, ACell notFound) {
241241
MapEntry<K, V> me = getEntry((K) key);
242242
if (me == null) {
243243
return (V) notFound;

convex-core/src/main/java/convex/core/data/ARecord.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ protected ARecord toCanonical() {
5353
return true;
5454
}
5555

56-
57-
5856
/**
5957
* Gets a vector of keys for this record
6058
*
@@ -161,7 +159,6 @@ public final AMap<Keyword, ACell> dissoc(ACell key) {
161159

162160
@Override
163161
public MapEntry<Keyword, ACell> getKeyRefEntry(Ref<ACell> keyRef) {
164-
// TODO: could maybe be more efficient?
165162
return getEntry(keyRef.getValue());
166163
}
167164

@@ -228,8 +225,16 @@ public boolean print(BlobBuilder sb, long limit) {
228225

229226
@Override
230227
public MapEntry<Keyword, ACell> getEntry(ACell k) {
231-
if (!containsKey(k)) return null;
232-
return MapEntry.create((Keyword)k,get(k));
228+
ACell v=get(k);
229+
if ((v==null)&&!containsKey(k)) return null; //if null, need to check if key exists
230+
return MapEntry.create((Keyword)k,v);
231+
}
232+
233+
@Override
234+
public ACell get(ACell key, ACell notFound) {
235+
ACell v=get(key);
236+
if ((v==null)&&!containsKey(key)) return notFound; //if null, need to check if key exists
237+
return v;
233238
}
234239

235240
@Override

convex-core/src/main/java/convex/core/data/AccountStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public static AccountStatus read(Blob b, int pos) throws BadFormatException {
192192
};
193193
Address controller=null;
194194
if ((included&HAS_CONTROLLER)!=0) {
195-
controller=Format.read(b, epos); // TODO should be raw Address, save a byte?
195+
controller=Format.read(b, epos);
196196
epos+=controller.getEncodingLength();
197197
}
198198
AHashMap<Symbol, ACell> environment = null;

convex-core/src/main/java/convex/core/data/Address.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ public final int getBytes(byte[] bs, int pos) {
303303

304304
@Override
305305
public long longValue() {
306-
// TODO Auto-generated method stub
307306
return value;
308307
}
309308

convex-core/src/main/java/convex/core/data/Cells.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.function.Consumer;
77

88
import convex.core.Result;
9+
import convex.core.data.impl.DummyCell;
910
import convex.core.exceptions.ParseException;
1011
import convex.core.store.AStore;
1112
import convex.core.store.Stores;
@@ -27,6 +28,8 @@ public class Cells {
2728
*/
2829
public static final int MAX_BRANCH_COUNT = 68;
2930

31+
public static final ACell DUMMY = new DummyCell();
32+
3033
/**
3134
* Equality method allowing for nulls
3235
*
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package convex.core.data.impl;
2+
3+
import convex.core.data.ACell;
4+
import convex.core.data.Tag;
5+
import convex.core.data.util.BlobBuilder;
6+
import convex.core.exceptions.InvalidDataException;
7+
8+
/**
9+
* A dummy cell implementation, not a valid CVM value
10+
*/
11+
public class DummyCell extends ACell {
12+
13+
@Override
14+
public int estimatedEncodingSize() {
15+
return 1;
16+
}
17+
18+
@Override
19+
public void validateCell() throws InvalidDataException {
20+
throw new InvalidDataException("This is a dummy value",this);
21+
}
22+
23+
@Override
24+
protected byte getTag() {
25+
return Tag.ILLEGAL;
26+
}
27+
28+
@Override
29+
public boolean equals(ACell a) {
30+
return this==a;
31+
}
32+
33+
@Override
34+
public int encode(byte[] bs, int pos) {
35+
bs[pos++]=Tag.ILLEGAL;
36+
return pos;
37+
}
38+
39+
@Override
40+
protected int encodeRaw(byte[] bs, int pos) {
41+
// Nothing to encode
42+
return pos;
43+
}
44+
45+
@Override
46+
public boolean isCanonical() {
47+
return true;
48+
}
49+
50+
@Override
51+
protected ACell toCanonical() {
52+
return this;
53+
}
54+
55+
@Override
56+
public boolean isCVMValue() {
57+
return false;
58+
}
59+
60+
@Override
61+
public boolean isDataValue() {
62+
return false;
63+
}
64+
65+
@Override
66+
public boolean print(BlobBuilder sb, long limit) {
67+
sb.append("DUMMY");
68+
return sb.check(limit);
69+
}
70+
71+
72+
73+
}

0 commit comments

Comments
 (0)