diff --git a/convex-core/src/main/java/convex/core/data/ACell.java b/convex-core/src/main/java/convex/core/data/ACell.java index 2bdc85de7..91be0f042 100644 --- a/convex-core/src/main/java/convex/core/data/ACell.java +++ b/convex-core/src/main/java/convex/core/data/ACell.java @@ -518,7 +518,6 @@ public T mark(Consumer> noveltyHandler) { return (T) this; } - /** * Creates a persisted Ref with the given value in the current store. * diff --git a/convex-core/src/main/java/convex/core/data/BlobMap.java b/convex-core/src/main/java/convex/core/data/BlobMap.java index b9e13b311..51da7ed87 100644 --- a/convex-core/src/main/java/convex/core/data/BlobMap.java +++ b/convex-core/src/main/java/convex/core/data/BlobMap.java @@ -118,7 +118,7 @@ public boolean isCanonical() { @SuppressWarnings("unchecked") @Override public BlobMap updateRefs(IRefFunction func) { - MapEntry newEntry = (entry == null) ? null : entry.updateRefs(func); + MapEntry newEntry = Ref.update(entry,func); Ref>[] newChildren = Ref.updateRefs(children, func); if ((entry == newEntry) && (children == newChildren)) return this; BlobMap result= new BlobMap(depth, prefixLength, newEntry, (Ref[])newChildren, mask, count); diff --git a/convex-core/src/main/java/convex/core/data/Ref.java b/convex-core/src/main/java/convex/core/data/Ref.java index 8684dea2d..b852965f5 100644 --- a/convex-core/src/main/java/convex/core/data/Ref.java +++ b/convex-core/src/main/java/convex/core/data/Ref.java @@ -672,6 +672,19 @@ public static int mergeFlags(int a, int b) { */ public abstract Ref ensureCanonical(); + /** + * Updates Refs in an arbitrary Cell + * @param Type of Cell + * @param o Cell to update + * @param func Ref update function + * @return Updated Cell (will be the same cell if Refs unchanged) + */ + @SuppressWarnings("unchecked") + public static T update(T o, IRefFunction func) { + if (o==null) return o; + return (T) o.updateRefs(func); + } + @SuppressWarnings("unchecked") public static R updateRefs(R a, IRefFunction func) { if (a==null) return null; diff --git a/convex-core/src/main/java/convex/core/transactions/Invoke.java b/convex-core/src/main/java/convex/core/transactions/Invoke.java index c73ed3315..1cc8ed67e 100644 --- a/convex-core/src/main/java/convex/core/transactions/Invoke.java +++ b/convex-core/src/main/java/convex/core/transactions/Invoke.java @@ -145,7 +145,7 @@ public Ref getRef(int i) { @Override public Invoke updateRefs(IRefFunction func) { - ACell newCommand = Utils.updateRefs(command, func); + ACell newCommand = Ref.update(command, func); if (newCommand == command) return this; return Invoke.create(origin,getSequence(), newCommand); } diff --git a/convex-core/src/main/java/convex/core/util/Utils.java b/convex-core/src/main/java/convex/core/util/Utils.java index 4005883f4..3457b4a82 100644 --- a/convex-core/src/main/java/convex/core/util/Utils.java +++ b/convex-core/src/main/java/convex/core/util/Utils.java @@ -39,7 +39,6 @@ import convex.core.data.AVector; import convex.core.data.Blob; import convex.core.data.BlobBuilder; -import convex.core.data.IRefFunction; import convex.core.data.Ref; import convex.core.data.Vectors; import convex.core.data.prim.CVMLong; @@ -1171,12 +1170,6 @@ public static Ref getRef(ACell o, int i) { return o.getRef(i); } - @SuppressWarnings("unchecked") - public static T updateRefs(T o, IRefFunction func) { - if (o==null) return o; - return (T) o.updateRefs(func); - } - public static int bitCount(short mask) { return Integer.bitCount(mask & 0xFFFF); } diff --git a/convex-core/src/test/java/convex/core/StateTest.java b/convex-core/src/test/java/convex/core/StateTest.java index c41093669..50b17e45a 100644 --- a/convex-core/src/test/java/convex/core/StateTest.java +++ b/convex-core/src/test/java/convex/core/StateTest.java @@ -83,11 +83,11 @@ public void testMultiCellTrip() throws BadFormatException { // Hash of a known value in the tree that should be encoded Hash check=Hash.fromHex("1fe0a93790d5e2a6d6d31db57edc611b128afe97941af611f65b703006ba5387"); - Refs.visitAllRefs(s.getRef(), r->{ - if (r.getHash().equals(check)) { - System.out.println(r.getValue()); - } - }); + //Refs.visitAllRefs(s.getRef(), r->{ + // if (r.getHash().equals(check)) { + // System.out.println(r.getValue()); + // } + //}); Blob b=Format.encodeMultiCell(s);