Skip to content

Commit ae7acfe

Browse files
committed
wait on 2-tuples as MapEntries until reassessment of tuples under direct linking
1 parent bfe14ae commit ae7acfe

13 files changed

+27
-55
lines changed

src/clj/clojure/core.clj

+1-4
Original file line numberDiff line numberDiff line change
@@ -1429,10 +1429,7 @@
14291429
"Return true if x is a map entry"
14301430
{:added "1.8"}
14311431
[x]
1432-
(and (instance? java.util.Map$Entry x)
1433-
(if (instance? clojure.lang.IPersistentVector x)
1434-
(= 2 (count x))
1435-
true)))
1432+
(instance? java.util.Map$Entry x))
14361433

14371434
(defn contains?
14381435
"Returns true if key is present in the given collection, otherwise

src/clj/clojure/core_deftype.clj

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@
212212
`(containsKey [this# k#] (not (identical? this# (.valAt this# k# this#))))
213213
`(entryAt [this# k#] (let [v# (.valAt this# k# this#)]
214214
(when-not (identical? this# v#)
215-
(clojure.lang.Tuple/create k# v#))))
216-
`(seq [this#] (seq (concat [~@(map #(list `clojure.lang.Tuple/create (keyword %) %) base-fields)]
215+
(clojure.lang.MapEntry/create k# v#))))
216+
`(seq [this#] (seq (concat [~@(map #(list `clojure.lang.MapEntry/create (keyword %) %) base-fields)]
217217
~'__extmap)))
218218
`(iterator [~gs]
219219
(clojure.lang.RecordIterator. ~gs [~@(map keyword base-fields)] (RT/iter ~'__extmap)))

src/clj/clojure/core_proxy.clj

+2-2
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@
400400
[]
401401
(iterator [] (.iterator ^Iterable pmap))
402402
(containsKey [k] (contains? pmap k))
403-
(entryAt [k] (when (contains? pmap k) (clojure.lang.Tuple/create k (v k))))
403+
(entryAt [k] (when (contains? pmap k) (clojure.lang.MapEntry/create k (v k))))
404404
(valAt ([k] (when (contains? pmap k) (v k)))
405405
([k default] (if (contains? pmap k) (v k) default)))
406406
(cons [m] (conj (snapshot) m))
@@ -410,7 +410,7 @@
410410
(seq [] ((fn thisfn [plseq]
411411
(lazy-seq
412412
(when-let [pseq (seq plseq)]
413-
(cons (clojure.lang.Tuple/create (first pseq) (v (first pseq)))
413+
(cons (clojure.lang.MapEntry/create (first pseq) (v (first pseq)))
414414
(thisfn (rest pseq)))))) (keys pmap))))))
415415

416416

src/clj/clojure/gvec.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@
267267
(< (int k) cnt)))
268268
(entryAt [this k]
269269
(if (.containsKey this k)
270-
(clojure.lang.Tuple/create k (.nth this (int k)))
270+
(clojure.lang.MapEntry/create k (.nth this (int k)))
271271
nil))
272272

273273
clojure.lang.ILookup

src/jvm/clojure/lang/APersistentMap.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public void remove() {
266266

267267
static final IFn MAKE_ENTRY = new AFn() {
268268
public Object invoke(Object key, Object val) {
269-
return Tuple.create(key, val);
269+
return MapEntry.create(key, val);
270270
}
271271
};
272272

src/jvm/clojure/lang/APersistentVector.java

+2-31
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.util.*;
1717

1818
public abstract class APersistentVector extends AFn implements IPersistentVector, Iterable,
19-
List, IMapEntry,
19+
List,
2020
RandomAccess, Comparable,
2121
Serializable, IHashEq {
2222
int _hash = -1;
@@ -126,21 +126,6 @@ else if(obj instanceof List)
126126

127127
}
128128

129-
@Override
130-
public Object getKey(){
131-
return key();
132-
}
133-
134-
@Override
135-
public Object getValue(){
136-
return val();
137-
}
138-
139-
@Override
140-
public Object setValue(Object value){
141-
throw new UnsupportedOperationException();
142-
}
143-
144129
public boolean equals(Object obj){
145130
if(obj == this)
146131
return true;
@@ -346,7 +331,7 @@ public IMapEntry entryAt(Object key){
346331
{
347332
int i = ((Number) key).intValue();
348333
if(i >= 0 && i < count())
349-
return (IMapEntry) Tuple.create(key, nth(i));
334+
return (IMapEntry) MapEntry.create(key, nth(i));
350335
}
351336
return null;
352337
}
@@ -456,20 +441,6 @@ else if(count() > v.count())
456441
return 0;
457442
}
458443

459-
@Override
460-
public Object key(){
461-
if(count() == 2)
462-
return nth(0);
463-
throw new UnsupportedOperationException();
464-
}
465-
466-
@Override
467-
public Object val(){
468-
if(count() == 2)
469-
return nth(1);
470-
throw new UnsupportedOperationException();
471-
}
472-
473444
static class Seq extends ASeq implements IndexedSeq, IReduce{
474445
//todo - something more efficient
475446
final IPersistentVector v;

src/jvm/clojure/lang/MapEntry.java

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ public class MapEntry extends AMapEntry{
1616
final Object _key;
1717
final Object _val;
1818

19+
static public MapEntry create(Object key, Object val){
20+
return new MapEntry(key, val);
21+
}
22+
1923
public MapEntry(Object key, Object val){
2024
this._key = key;
2125
this._val = val;

src/jvm/clojure/lang/PersistentArrayMap.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ static public IPersistentMap create(Map other){
3939
ITransientMap ret = EMPTY.asTransient();
4040
for(Object o : other.entrySet())
4141
{
42-
Map.Entry e = (Entry) o;
43-
ret = ret.assoc(e.getKey(), e.getValue());
42+
Map.Entry e = (Entry) o;
43+
ret = ret.assoc(e.getKey(), e.getValue());
4444
}
4545
return ret.persistent();
4646
}
@@ -164,7 +164,7 @@ public boolean containsKey(Object key){
164164
public IMapEntry entryAt(Object key){
165165
int i = indexOf(key);
166166
if(i >= 0)
167-
return (IMapEntry) Tuple.create(array[i],array[i+1]);
167+
return (IMapEntry) MapEntry.create(array[i],array[i+1]);
168168
return null;
169169
}
170170

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

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

320320
public ISeq next(){

src/jvm/clojure/lang/PersistentHashMap.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public boolean containsKey(Object key){
128128

129129
public IMapEntry entryAt(Object key){
130130
if(key == null)
131-
return hasNull ? (IMapEntry) Tuple.create(null, nullValue) : null;
131+
return hasNull ? (IMapEntry) MapEntry.create(null, nullValue) : null;
132132
return (root != null) ? root.find(0, hash(key), key) : null;
133133
}
134134

@@ -264,7 +264,7 @@ public int count(){
264264

265265
public ISeq seq(){
266266
ISeq s = root != null ? root.nodeSeq() : null;
267-
return hasNull ? new Cons(Tuple.create(null, nullValue), s) : s;
267+
return hasNull ? new Cons(MapEntry.create(null, nullValue), s) : s;
268268
}
269269

270270
public IPersistentCollection empty(){
@@ -766,7 +766,7 @@ public IMapEntry find(int shift, int hash, Object key){
766766
if(keyOrNull == null)
767767
return ((INode) valOrNode).find(shift + 5, hash, key);
768768
if(Util.equiv(key, keyOrNull))
769-
return (IMapEntry) Tuple.create(keyOrNull, valOrNode);
769+
return (IMapEntry) MapEntry.create(keyOrNull, valOrNode);
770770
return null;
771771
}
772772

@@ -967,7 +967,7 @@ public IMapEntry find(int shift, int hash, Object key){
967967
if(idx < 0)
968968
return null;
969969
if(Util.equiv(key, array[idx]))
970-
return (IMapEntry) Tuple.create(array[idx], array[idx+1]);
970+
return (IMapEntry) MapEntry.create(array[idx], array[idx+1]);
971971
return null;
972972
}
973973

@@ -1343,7 +1343,7 @@ public Obj withMeta(IPersistentMap meta) {
13431343
public Object first() {
13441344
if(s != null)
13451345
return s.first();
1346-
return Tuple.create(array[i], array[i+1]);
1346+
return MapEntry.create(array[i], array[i+1]);
13471347
}
13481348

13491349
public ISeq next() {

src/jvm/clojure/lang/PersistentStructMap.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public IMapEntry entryAt(Object key){
132132
Map.Entry e = def.keyslots.entryAt(key);
133133
if(e != null)
134134
{
135-
return (IMapEntry) Tuple.create(e.getKey(), vals[(Integer) e.getValue()]);
135+
return (IMapEntry) MapEntry.create(e.getKey(), vals[(Integer) e.getValue()]);
136136
}
137137
return ext.entryAt(key);
138138
}
@@ -245,7 +245,7 @@ public Obj withMeta(IPersistentMap meta){
245245
}
246246

247247
public Object first(){
248-
return Tuple.create(keys.first(), vals[i]);
248+
return MapEntry.create(keys.first(), vals[i]);
249249
}
250250

251251
public ISeq next(){

src/jvm/clojure/lang/RT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ else if(coll instanceof Associative)
822822
else {
823823
Map m = (Map) coll;
824824
if(m.containsKey(key))
825-
return Tuple.create(key, m.get(key));
825+
return MapEntry.create(key, m.get(key));
826826
return null;
827827
}
828828
}

src/jvm/clojure/lang/RecordIterator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Object next() {
4141
if (i < basecnt) {
4242
Object k = basefields.nth(i);
4343
i++;
44-
return Tuple.create(k, rec.valAt(k));
44+
return MapEntry.create(k, rec.valAt(k));
4545
} else {
4646
return extmap.next();
4747
}

test/clojure/test_clojure/data_structures.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@
712712
(testing "map-entry? = true"
713713
(are [entry]
714714
(true? (map-entry? entry))
715-
[1 2] (first (doto (java.util.HashMap.) (.put "x" 1))))))
715+
(first (doto (java.util.HashMap.) (.put "x" 1))))))
716716

717717
;; *** Sets ***
718718

0 commit comments

Comments
 (0)