Skip to content

Commit 2d2babf

Browse files
committed
Fix AbstractHost.remove
Fixes #2279
1 parent 135d1ea commit 2d2babf

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

src/main/java/soot/tagkit/AbstractHost.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
import java.util.Collections;
26+
import java.util.Iterator;
2627
import java.util.List;
2728
import java.util.function.Supplier;
2829

@@ -59,27 +60,17 @@ public List<Tag> getTags() {
5960
*/
6061
@Override
6162
public void removeTag(String aName) {
62-
int tagIndex = searchForTag(aName);
63-
if (tagIndex != -1) {
64-
mTagList.remove(tagIndex);
65-
}
66-
}
67-
68-
/**
69-
* Search for {@link Tag} named {@code aName}.
70-
*/
71-
private int searchForTag(String aName) {
72-
if (mTagList != null) {
73-
for (int i = 0; i < mTagList.size(); i++) {
74-
Tag tag = mTagList.get(i);
75-
if (tag != null && tag.getName().equals(aName)) {
76-
return i;
77-
}
63+
Iterator<Tag> it = mTagList.iterator();
64+
while (it.hasNext()) {
65+
Tag tag = it.next();
66+
if (tag != null && tag.getName().equals(aName)) {
67+
it.remove();
68+
break;
7869
}
7970
}
80-
return -1;
8171
}
8272

73+
8374
/**
8475
* Return the {@link Tag} named {@code aName} from {@code this} {@link Host} or {@code null} if there is no such
8576
* {@link Tag}.
@@ -110,7 +101,14 @@ public Tag getTag(String aName) {
110101
*/
111102
@Override
112103
public boolean hasTag(String aName) {
113-
return (searchForTag(aName) != -1);
104+
if (mTagList != null) {
105+
for (Tag tag : mTagList) {
106+
if (tag != null && tag.getName().equals(aName)) {
107+
return true;
108+
}
109+
}
110+
}
111+
return false;
114112
}
115113

116114
/**

0 commit comments

Comments
 (0)