Skip to content

Commit c6467b4

Browse files
brandonbloomstuarthalloway
authored andcommitted
Improves RestFn and ArraySeq perf
Eliminates a call to java.lang.Class.getComponentType, since the result will always Object.class and that makes downstream uses nops. Signed-off-by: Stuart Halloway <[email protected]>
1 parent e7f55e8 commit c6467b4

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/jvm/clojure/lang/ArraySeq.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class ArraySeq extends ASeq implements IndexedSeq, IReduce{
1818
public final Object array;
1919
final int i;
2020
final Object[] oa;
21-
final Class ct;
2221
//ISeq _rest;
2322

2423
static public ArraySeq create(){
@@ -54,7 +53,6 @@ static ISeq createFromObject(Object array){
5453

5554
ArraySeq(Object array, int i){
5655
this.array = array;
57-
this.ct = array.getClass().getComponentType();
5856
this.i = i;
5957
this.oa = (Object[]) (array instanceof Object[] ? array : null);
6058
// this._rest = this;
@@ -63,15 +61,14 @@ static ISeq createFromObject(Object array){
6361
ArraySeq(IPersistentMap meta, Object array, int i){
6462
super(meta);
6563
this.array = array;
66-
this.ct = array.getClass().getComponentType();
6764
this.i = i;
6865
this.oa = (Object[]) (array instanceof Object[] ? array : null);
6966
}
7067

7168
public Object first(){
7269
if(oa != null)
7370
return oa[i];
74-
return Reflector.prepRet(ct, Array.get(array, i));
71+
return Reflector.prepRet(Object.class, Array.get(array, i));
7572
}
7673

7774
public ISeq next(){
@@ -111,9 +108,9 @@ public Object reduce(IFn f) {
111108
return ret;
112109
}
113110

114-
Object ret = Reflector.prepRet(ct, Array.get(array, i));
111+
Object ret = Reflector.prepRet(Object.class, Array.get(array, i));
115112
for(int x = i + 1; x < Array.getLength(array); x++)
116-
ret = f.invoke(ret, Reflector.prepRet(ct, Array.get(array, x)));
113+
ret = f.invoke(ret, Reflector.prepRet(Object.class, Array.get(array, x)));
117114
return ret;
118115
}
119116

@@ -125,9 +122,9 @@ public Object reduce(IFn f, Object start) {
125122
ret = f.invoke(ret, oa[x]);
126123
return ret;
127124
}
128-
Object ret = f.invoke(start, Reflector.prepRet(ct, Array.get(array, i)));
125+
Object ret = f.invoke(start, Reflector.prepRet(Object.class, Array.get(array, i)));
129126
for(int x = i + 1; x < Array.getLength(array); x++)
130-
ret = f.invoke(ret, Reflector.prepRet(ct, Array.get(array, x)));
127+
ret = f.invoke(ret, Reflector.prepRet(Object.class, Array.get(array, x)));
131128
return ret;
132129
}
133130

@@ -138,7 +135,7 @@ public int indexOf(Object o) {
138135
} else {
139136
int n = Array.getLength(array);
140137
for (int j = i; j < n; j++)
141-
if (Util.equals(o, Reflector.prepRet(ct, Array.get(array, j)))) return j - i;
138+
if (Util.equals(o, Reflector.prepRet(Object.class, Array.get(array, j)))) return j - i;
142139
}
143140
return -1;
144141
}
@@ -155,10 +152,10 @@ public int lastIndexOf(Object o) {
155152
} else {
156153
if (o == null) {
157154
for (int j = Array.getLength(array) - 1 ; j >= i; j--)
158-
if (Reflector.prepRet(ct, Array.get(array, j)) == null) return j - i;
155+
if (Reflector.prepRet(Object.class, Array.get(array, j)) == null) return j - i;
159156
} else {
160157
for (int j = Array.getLength(array) - 1 ; j >= i; j--)
161-
if (o.equals(Reflector.prepRet(ct, Array.get(array, j)))) return j - i;
158+
if (o.equals(Reflector.prepRet(Object.class, Array.get(array, j)))) return j - i;
162159
}
163160
}
164161
return -1;

0 commit comments

Comments
 (0)