Skip to content

Commit

Permalink
[JENKINS-39404 Follow-up] Minimize write to disk for non-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Nov 1, 2016
1 parent 53cc6b2 commit e7f63ac
Showing 1 changed file with 16 additions and 5 deletions.
Expand Up @@ -300,13 +300,18 @@ public void replaceAction(Action a) {
// CopyOnWriteArrayList does not support Iterator.remove, so need to do it this way:
List<Action> old = new ArrayList<Action>(1);
List<Action> current = super.getActions();
boolean found = false;
for (Action a2 : current) {
if (a2.getClass() == a.getClass()) {
if (!found && a.equals(a2)) {
found = true;
} else if (a2.getClass() == a.getClass()) {
old.add(a2);
}
}
current.removeAll(old);
addAction(a);
if (!found) {
addAction(a);
}
}

/**
Expand Down Expand Up @@ -361,20 +366,26 @@ public boolean removeActions(@Nonnull Class<? extends Action> clazz) {
// @Override // TODO uncomment once baseline has JENKINS-39404
@SuppressWarnings({"ConstantConditions", "deprecation"})
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
public void replaceActions(@Nonnull Class<? extends Action> clazz, Action a) {
public boolean replaceActions(@Nonnull Class<? extends Action> clazz, Action a) {
if (clazz == null) {
throw new IllegalArgumentException("Action type must be non-null");
}
// CopyOnWriteArrayList does not support Iterator.remove, so need to do it this way:
List<Action> old = new ArrayList<Action>();
List<Action> current = super.getActions();
boolean found = false;
for (Action a1 : current) {
if (clazz.isInstance(a1)) {
if (!found && a.equals(a1)) {
found = true;
} else if (clazz.isInstance(a1) && !a.equals(a1)) {
old.add(a1);
}
}
current.removeAll(old);
addAction(a);
if (!found) {
addAction(a);
}
return !(old.isEmpty() && found);
}

@Override
Expand Down

0 comments on commit e7f63ac

Please sign in to comment.