Skip to content

Commit

Permalink
wait on 2-tuples as MapEntries until reassessment of tuples under dir…
Browse files Browse the repository at this point in the history
…ect linking
  • Loading branch information
richhickey committed Dec 13, 2015
1 parent bfe14ae commit ae7acfe
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 55 deletions.
5 changes: 1 addition & 4 deletions src/clj/clojure/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1429,10 +1429,7 @@
"Return true if x is a map entry"
{:added "1.8"}
[x]
(and (instance? java.util.Map$Entry x)
(if (instance? clojure.lang.IPersistentVector x)
(= 2 (count x))
true)))
(instance? java.util.Map$Entry x))

(defn contains?
"Returns true if key is present in the given collection, otherwise
Expand Down
4 changes: 2 additions & 2 deletions src/clj/clojure/core_deftype.clj
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@
`(containsKey [this# k#] (not (identical? this# (.valAt this# k# this#))))
`(entryAt [this# k#] (let [v# (.valAt this# k# this#)]
(when-not (identical? this# v#)
(clojure.lang.Tuple/create k# v#))))
`(seq [this#] (seq (concat [~@(map #(list `clojure.lang.Tuple/create (keyword %) %) base-fields)]
(clojure.lang.MapEntry/create k# v#))))
`(seq [this#] (seq (concat [~@(map #(list `clojure.lang.MapEntry/create (keyword %) %) base-fields)]
~'__extmap)))
`(iterator [~gs]
(clojure.lang.RecordIterator. ~gs [~@(map keyword base-fields)] (RT/iter ~'__extmap)))
Expand Down
4 changes: 2 additions & 2 deletions src/clj/clojure/core_proxy.clj
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@
[]
(iterator [] (.iterator ^Iterable pmap))
(containsKey [k] (contains? pmap k))
(entryAt [k] (when (contains? pmap k) (clojure.lang.Tuple/create k (v k))))
(entryAt [k] (when (contains? pmap k) (clojure.lang.MapEntry/create k (v k))))
(valAt ([k] (when (contains? pmap k) (v k)))
([k default] (if (contains? pmap k) (v k) default)))
(cons [m] (conj (snapshot) m))
Expand All @@ -410,7 +410,7 @@
(seq [] ((fn thisfn [plseq]
(lazy-seq
(when-let [pseq (seq plseq)]
(cons (clojure.lang.Tuple/create (first pseq) (v (first pseq)))
(cons (clojure.lang.MapEntry/create (first pseq) (v (first pseq)))
(thisfn (rest pseq)))))) (keys pmap))))))


Expand Down
2 changes: 1 addition & 1 deletion src/clj/clojure/gvec.clj
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
(< (int k) cnt)))
(entryAt [this k]
(if (.containsKey this k)
(clojure.lang.Tuple/create k (.nth this (int k)))
(clojure.lang.MapEntry/create k (.nth this (int k)))
nil))

clojure.lang.ILookup
Expand Down
2 changes: 1 addition & 1 deletion src/jvm/clojure/lang/APersistentMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public void remove() {

static final IFn MAKE_ENTRY = new AFn() {
public Object invoke(Object key, Object val) {
return Tuple.create(key, val);
return MapEntry.create(key, val);
}
};

Expand Down
33 changes: 2 additions & 31 deletions src/jvm/clojure/lang/APersistentVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.*;

public abstract class APersistentVector extends AFn implements IPersistentVector, Iterable,
List, IMapEntry,
List,
RandomAccess, Comparable,
Serializable, IHashEq {
int _hash = -1;
Expand Down Expand Up @@ -126,21 +126,6 @@ else if(obj instanceof List)

}

@Override
public Object getKey(){
return key();
}

@Override
public Object getValue(){
return val();
}

@Override
public Object setValue(Object value){
throw new UnsupportedOperationException();
}

public boolean equals(Object obj){
if(obj == this)
return true;
Expand Down Expand Up @@ -346,7 +331,7 @@ public IMapEntry entryAt(Object key){
{
int i = ((Number) key).intValue();
if(i >= 0 && i < count())
return (IMapEntry) Tuple.create(key, nth(i));
return (IMapEntry) MapEntry.create(key, nth(i));
}
return null;
}
Expand Down Expand Up @@ -456,20 +441,6 @@ else if(count() > v.count())
return 0;
}

@Override
public Object key(){
if(count() == 2)
return nth(0);
throw new UnsupportedOperationException();
}

@Override
public Object val(){
if(count() == 2)
return nth(1);
throw new UnsupportedOperationException();
}

static class Seq extends ASeq implements IndexedSeq, IReduce{
//todo - something more efficient
final IPersistentVector v;
Expand Down
4 changes: 4 additions & 0 deletions src/jvm/clojure/lang/MapEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class MapEntry extends AMapEntry{
final Object _key;
final Object _val;

static public MapEntry create(Object key, Object val){
return new MapEntry(key, val);
}

public MapEntry(Object key, Object val){
this._key = key;
this._val = val;
Expand Down
8 changes: 4 additions & 4 deletions src/jvm/clojure/lang/PersistentArrayMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ static public IPersistentMap create(Map other){
ITransientMap ret = EMPTY.asTransient();
for(Object o : other.entrySet())
{
Map.Entry e = (Entry) o;
ret = ret.assoc(e.getKey(), e.getValue());
Map.Entry e = (Entry) o;
ret = ret.assoc(e.getKey(), e.getValue());
}
return ret.persistent();
}
Expand Down Expand Up @@ -164,7 +164,7 @@ public boolean containsKey(Object key){
public IMapEntry entryAt(Object key){
int i = indexOf(key);
if(i >= 0)
return (IMapEntry) Tuple.create(array[i],array[i+1]);
return (IMapEntry) MapEntry.create(array[i],array[i+1]);
return null;
}

Expand Down Expand Up @@ -314,7 +314,7 @@ public Seq(IPersistentMap meta, Object[] array, int i){
}

public Object first(){
return Tuple.create(array[i],array[i+1]);
return MapEntry.create(array[i],array[i+1]);
}

public ISeq next(){
Expand Down
10 changes: 5 additions & 5 deletions src/jvm/clojure/lang/PersistentHashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public boolean containsKey(Object key){

public IMapEntry entryAt(Object key){
if(key == null)
return hasNull ? (IMapEntry) Tuple.create(null, nullValue) : null;
return hasNull ? (IMapEntry) MapEntry.create(null, nullValue) : null;
return (root != null) ? root.find(0, hash(key), key) : null;
}

Expand Down Expand Up @@ -264,7 +264,7 @@ public int count(){

public ISeq seq(){
ISeq s = root != null ? root.nodeSeq() : null;
return hasNull ? new Cons(Tuple.create(null, nullValue), s) : s;
return hasNull ? new Cons(MapEntry.create(null, nullValue), s) : s;
}

public IPersistentCollection empty(){
Expand Down Expand Up @@ -766,7 +766,7 @@ public IMapEntry find(int shift, int hash, Object key){
if(keyOrNull == null)
return ((INode) valOrNode).find(shift + 5, hash, key);
if(Util.equiv(key, keyOrNull))
return (IMapEntry) Tuple.create(keyOrNull, valOrNode);
return (IMapEntry) MapEntry.create(keyOrNull, valOrNode);
return null;
}

Expand Down Expand Up @@ -967,7 +967,7 @@ public IMapEntry find(int shift, int hash, Object key){
if(idx < 0)
return null;
if(Util.equiv(key, array[idx]))
return (IMapEntry) Tuple.create(array[idx], array[idx+1]);
return (IMapEntry) MapEntry.create(array[idx], array[idx+1]);
return null;
}

Expand Down Expand Up @@ -1343,7 +1343,7 @@ public Obj withMeta(IPersistentMap meta) {
public Object first() {
if(s != null)
return s.first();
return Tuple.create(array[i], array[i+1]);
return MapEntry.create(array[i], array[i+1]);
}

public ISeq next() {
Expand Down
4 changes: 2 additions & 2 deletions src/jvm/clojure/lang/PersistentStructMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public IMapEntry entryAt(Object key){
Map.Entry e = def.keyslots.entryAt(key);
if(e != null)
{
return (IMapEntry) Tuple.create(e.getKey(), vals[(Integer) e.getValue()]);
return (IMapEntry) MapEntry.create(e.getKey(), vals[(Integer) e.getValue()]);
}
return ext.entryAt(key);
}
Expand Down Expand Up @@ -245,7 +245,7 @@ public Obj withMeta(IPersistentMap meta){
}

public Object first(){
return Tuple.create(keys.first(), vals[i]);
return MapEntry.create(keys.first(), vals[i]);
}

public ISeq next(){
Expand Down
2 changes: 1 addition & 1 deletion src/jvm/clojure/lang/RT.java
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ else if(coll instanceof Associative)
else {
Map m = (Map) coll;
if(m.containsKey(key))
return Tuple.create(key, m.get(key));
return MapEntry.create(key, m.get(key));
return null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/jvm/clojure/lang/RecordIterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Object next() {
if (i < basecnt) {
Object k = basefields.nth(i);
i++;
return Tuple.create(k, rec.valAt(k));
return MapEntry.create(k, rec.valAt(k));
} else {
return extmap.next();
}
Expand Down
2 changes: 1 addition & 1 deletion test/clojure/test_clojure/data_structures.clj
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@
(testing "map-entry? = true"
(are [entry]
(true? (map-entry? entry))
[1 2] (first (doto (java.util.HashMap.) (.put "x" 1))))))
(first (doto (java.util.HashMap.) (.put "x" 1))))))

;; *** Sets ***

Expand Down

0 comments on commit ae7acfe

Please sign in to comment.