Skip to content

Commit

Permalink
Iterate over map entries more efficiently
Browse files Browse the repository at this point in the history
Use iteration over key-value pairs, not over keys. The later is less
efficient, as it needs to construct a temporary Set of keys.

Remove attributes to suppress corresponding FindBugs issues.
  • Loading branch information
proski authored and jakub-bochenski committed Apr 24, 2019
1 parent b550858 commit fc28fa2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.kohsuke.stapler.StaplerRequest;

/** Created by Nathan McCarthy */
@SuppressFBWarnings({"WMI_WRONG_MAP_ITERATOR", "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE"})
@SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
public class StashBuildTrigger extends Trigger<AbstractProject<?, ?>> {
private static final Logger logger =
Logger.getLogger(MethodHandles.lookup().lookupClass().getName());
Expand Down Expand Up @@ -220,8 +220,8 @@ public QueueTaskFuture<?> startJob(StashCause cause) {

Map<String, String> additionalParameters = cause.getAdditionalParameters();
if (additionalParameters != null) {
for (String parameter : additionalParameters.keySet()) {
values.add(new StringParameterValue(parameter, additionalParameters.get(parameter)));
for (Map.Entry<String, String> parameter : additionalParameters.entrySet()) {
values.add(new StringParameterValue(parameter.getKey(), parameter.getValue()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static java.lang.String.format;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.model.Result;
import java.lang.invoke.MethodHandles;
import java.util.AbstractMap;
Expand All @@ -22,7 +21,6 @@
import stashpullrequestbuilder.stashpullrequestbuilder.stash.StashPullRequestResponseValueRepository;

/** Created by Nathan McCarthy */
@SuppressFBWarnings("WMI_WRONG_MAP_ITERATOR")
public class StashRepository {
private static final Logger logger =
Logger.getLogger(MethodHandles.lookup().lookupClass().getName());
Expand Down Expand Up @@ -144,8 +142,8 @@ public Map<String, String> getAdditionalParameters(StashPullRequestResponseValue
}

Map<String, String> parameters = getParametersFromContent(content);
for (String key : parameters.keySet()) {
result.put(key, parameters.get(key));
for (Map.Entry<String, String> parameter : parameters.entrySet()) {
result.put(parameter.getKey(), parameter.getValue());
}
}
return result;
Expand Down

0 comments on commit fc28fa2

Please sign in to comment.