Skip to content
Permalink
Browse files
[JENKINS-39404 Follow-up] Minimize write to disk for non-changes
  • Loading branch information
stephenc committed Nov 1, 2016
1 parent 53cc6b2 commit e7f63ac9128b4b31bdc32b2cb06182d315a6d859
Showing with 16 additions and 5 deletions.
  1. +16 −5 src/main/java/com/cloudbees/hudson/plugins/folder/AbstractFolder.java
@@ -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);
}
}

/**
@@ -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

0 comments on commit e7f63ac

Please sign in to comment.