diff options
author | Rich Hickey <richhickey@gmail.com> | 2006-09-25 14:05:29 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2006-09-25 14:05:29 +0000 |
commit | 7608103759042de92448c70cc4dc9cbabc38f44b (patch) | |
tree | d1bea31af55188e826d6c53b7c6f8bf58a8f853b | |
parent | db5107d5d868cdd95e5af40cc9ab02f0261df7f4 (diff) |
fixed rest(), made first/rest fully synched
-rw-r--r-- | src/jvm/clojure/lang/IteratorSeq.java | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/src/jvm/clojure/lang/IteratorSeq.java b/src/jvm/clojure/lang/IteratorSeq.java index dc266279..20102034 100644 --- a/src/jvm/clojure/lang/IteratorSeq.java +++ b/src/jvm/clojure/lang/IteratorSeq.java @@ -14,43 +14,39 @@ import java.util.Iterator; public class IteratorSeq extends ASeq{
Iterator iter;
-volatile Object val;
-volatile ISeq _rest;
+Object val;
+ISeq _rest;
public static IteratorSeq create(Iterator iter){
- if(iter.hasNext())
- return new IteratorSeq(iter);
- return null;
+ if(iter.hasNext())
+ return new IteratorSeq(iter);
+ return null;
}
IteratorSeq(Iterator iter){
- this.iter = iter;
- this.val = this;
- this._rest = this;
+ this.iter = iter;
+ this.val = this;
+ this._rest = this;
}
-public Object first() {
- if(val == this)
- {
- synchronized(this){
- if(val == this)
- val = iter.next();
- }
- }
- return val;
+public Object first(){
+ synchronized(this)
+ {
+ if(val == this)
+ val = iter.next();
+ return val;
+ }
}
-public ISeq rest() {
- if(_rest == this)
- {
- synchronized(this){
- if(_rest == this)
- {
- first();
- _rest = new IteratorSeq(iter);
- }
- }
- }
- return _rest;
+public ISeq rest(){
+ synchronized(this)
+ {
+ if(_rest == this)
+ {
+ first();
+ _rest = create(iter);
+ }
+ return _rest;
+ }
}
}
|