Skip to content

Commit 3e4bf71

Browse files
halgaristuarthalloway
authored andcommitted
make sure Java files respect Reduced
deref reduced vals Signed-off-by: Stuart Halloway <stu@cognitect.com>
1 parent f149260 commit 3e4bf71

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/jvm/clojure/lang/APersistentVector.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -469,15 +469,19 @@ public APersistentVector.Seq withMeta(IPersistentMap meta){
469469

470470
public Object reduce(IFn f) {
471471
Object ret = v.nth(i);
472-
for(int x = i + 1; x < v.count(); x++)
473-
ret = f.invoke(ret, v.nth(x));
472+
for(int x = i + 1; x < v.count(); x++) {
473+
ret = f.invoke(ret, v.nth(x));
474+
if (RT.isReduced(ret)) return ((IDeref)ret).deref();
475+
}
474476
return ret;
475477
}
476478

477479
public Object reduce(IFn f, Object start) {
478480
Object ret = f.invoke(start, v.nth(i));
479-
for(int x = i + 1; x < v.count(); x++)
480-
ret = f.invoke(ret, v.nth(x));
481+
for(int x = i + 1; x < v.count(); x++) {
482+
if (RT.isReduced(ret)) return ((IDeref)ret).deref();
483+
ret = f.invoke(ret, v.nth(x));
484+
}
481485
return ret;
482486
}
483487
}

src/jvm/clojure/lang/PersistentList.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,19 @@ public PersistentList withMeta(IPersistentMap meta){
113113

114114
public Object reduce(IFn f) {
115115
Object ret = first();
116-
for(ISeq s = next(); s != null; s = s.next())
117-
ret = f.invoke(ret, s.first());
116+
for(ISeq s = next(); s != null; s = s.next()) {
117+
ret = f.invoke(ret, s.first());
118+
if (RT.isReduced(ret)) return ((IDeref)ret).deref();;
119+
}
118120
return ret;
119121
}
120122

121123
public Object reduce(IFn f, Object start) {
122124
Object ret = f.invoke(start, first());
123-
for(ISeq s = next(); s != null; s = s.next())
124-
ret = f.invoke(ret, s.first());
125+
for(ISeq s = next(); s != null; s = s.next()) {
126+
if (RT.isReduced(ret)) return ((IDeref)ret).deref();
127+
ret = f.invoke(ret, s.first());
128+
}
125129
return ret;
126130
}
127131

0 commit comments

Comments
 (0)