Permalink
Browse files

Fix handling of Reduced values in PersistentTreeMap/kvreduce

It was dereferencing them and passing them up the chain; but that meant
that parent nodes didn't know the reduction had completed, so the
reduction might continue along other paths down the tree.

Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
  • Loading branch information...
1 parent 3c22b53 commit 87c6f2417cdd139e1dc32655b8f8a099d3dc4be5 @amalloy amalloy committed with stuarthalloway Aug 10, 2012
Showing with 5 additions and 5 deletions.
  1. +5 −5 src/jvm/clojure/lang/PersistentTreeMap.java
@@ -207,7 +207,9 @@ public NodeIterator iterator(){
public Object kvreduce(IFn f, Object init){
if(tree != null)
- return tree.kvreduce(f,init);
+ init = tree.kvreduce(f,init);
+ if(RT.isReduced(init))
+ init = ((IDeref)init).deref();
return init;
}
@@ -540,16 +542,14 @@ public Object kvreduce(IFn f, Object init){
if(left() != null){
init = left().kvreduce(f, init);
if(RT.isReduced(init))
- return ((IDeref)init).deref();
+ return init;
}
init = f.invoke(init, key(), val());
if(RT.isReduced(init))
- return ((IDeref)init).deref();
+ return init;
if(right() != null){
init = right().kvreduce(f, init);
- if(RT.isReduced(init))
- return ((IDeref)init).deref();
}
return init;
}

0 comments on commit 87c6f24

Please sign in to comment.