Skip to content

Commit

Permalink
perf: add PropertyIteratorImpl.EMPTY_ITERATOR when iterating over an …
Browse files Browse the repository at this point in the history
…empty collection
  • Loading branch information
vlsi committed Jun 14, 2023
1 parent cabc3fb commit 9793459
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,9 @@ public PropertyIterator propertyIterator() {
// Note: can't use ConcurrentMap here as it would return elements in unpredictable order
readLock();
try {
if (propMap.isEmpty()) {
return PropertyIteratorImpl.EMPTY_ITERATOR;
}
// TODO: copy the contents of the iterator to avoid ConcurrentModificationException?
return new PropertyIteratorImpl(this, propMap.values());
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public void setRunningVersion(boolean runningVersion) {
}

protected PropertyIterator getIterator(Collection<JMeterProperty> values) {
if (values.isEmpty()) {
return PropertyIteratorImpl.EMPTY_ITERATOR;
}
return new PropertyIteratorImpl(values);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
package org.apache.jmeter.testelement.property;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;

import org.apache.jmeter.testelement.TestElement;

public class PropertyIteratorImpl implements PropertyIterator {
public static final PropertyIterator EMPTY_ITERATOR = new PropertyIteratorImpl(Collections.emptyList());

private final TestElement owner;
private final Iterator<? extends JMeterProperty> iter;
Expand Down

0 comments on commit 9793459

Please sign in to comment.