Skip to content

Commit d32ef81

Browse files
committed
Remove obsolete method 'SequenceStorage.count'.
1 parent cfde06f commit d32ef81

File tree

4 files changed

+17
-21
lines changed

4 files changed

+17
-21
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
6969
import com.oracle.graal.python.nodes.control.GetIteratorNode;
7070
import com.oracle.graal.python.nodes.control.GetNextNode;
71+
import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
7172
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
7273
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
7374
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -91,6 +92,7 @@
9192
import com.oracle.truffle.api.dsl.TypeSystemReference;
9293
import com.oracle.truffle.api.profiles.BranchProfile;
9394
import com.oracle.truffle.api.profiles.ConditionProfile;
95+
import com.oracle.truffle.api.profiles.ValueProfile;
9496

9597
@CoreFunctions(extendClasses = PythonBuiltinClassType.PByteArray)
9698
public class ByteArrayBuiltins extends PythonBuiltins {
@@ -456,11 +458,23 @@ public int index(PByteArray byteArray, Object arg,
456458
// bytearray.count(x)
457459
@Builtin(name = "count", fixedNumOfPositionalArgs = 2)
458460
@GenerateNodeFactory
459-
public abstract static class ByteArrayCountNode extends PythonBuiltinNode {
461+
@ImportStatic(SpecialMethodNames.class)
462+
public abstract static class ByteArrayCountNode extends PythonBinaryBuiltinNode {
460463

461464
@Specialization
462-
public int count(PByteArray byteArray, Object arg) {
463-
return byteArray.count(arg);
465+
public int count(PByteArray byteArray, Object arg,
466+
@Cached("createClassProfile()") ValueProfile storeProfile,
467+
@Cached("createNotNormalized()") SequenceStorageNodes.GetItemNode getItemNode,
468+
@Cached("create(__EQ__, __EQ__, __EQ__)") BinaryComparisonNode eqNode) {
469+
470+
SequenceStorage profiled = storeProfile.profile(byteArray.getSequenceStorage());
471+
int cnt = 0;
472+
for (int i = 0; i < profiled.length(); i++) {
473+
if (eqNode.executeBool(arg, getItemNode.execute(profiled, i))) {
474+
cnt++;
475+
}
476+
}
477+
return cnt;
464478
}
465479
}
466480

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/PByteArray.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ public final void delSlice(PSlice slice) {
128128
store.delSlice(start, stop, step);
129129
}
130130

131-
public int count(Object arg) {
132-
return this.store.count(arg);
133-
}
134-
135131
@Override
136132
public PIBytesLike createFromBytes(PythonObjectFactory factory, byte[] bytes) {
137133
return factory.createByteArray(bytes);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/list/PList.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ public final int hashCode() {
171171
return super.hashCode();
172172
}
173173

174-
public int count(Object arg) {
175-
return store.count(arg);
176-
}
177-
178174
public static PList require(Object value) {
179175
if (value instanceof PList) {
180176
return (PList) value;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/sequence/storage/SequenceStorage.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,4 @@ public enum ListStorageType {
101101
public void clear() {
102102
this.delSlice(0, length(), 1);
103103
}
104-
105-
public int count(Object arg) {
106-
int count = 0;
107-
for (Object obj : getInternalArray()) {
108-
if (obj.equals(arg)) {
109-
count++;
110-
}
111-
}
112-
return count;
113-
}
114104
}

0 commit comments

Comments
 (0)