Source:
<code>public Set<Branch.NameKey> call() throws NoSuchProjectException, RepositoryNotFoundException, OrmException { final ProjectControl projectControl = projectControlFactory.controlFor(projectName); final Iterator<Branch.NameKey> branchIt = toRemove.iterator(); while (branchIt.hasNext()) { final Branch.NameKey k = branchIt.next(); if (!projectName.equals(k.getParentKey())) { throw new IllegalArgumentException("All keys must be from same project"); } if (!projectControl.controlForRef(k).canDelete()) { throw new IllegalStateException("Cannot delete " + k.getShortName()); } <START> if (!db.changes().byBranchOpenAll(k).toList().isEmpty()) { <END> branchIt.remove(); } } final Set<Branch.NameKey> deleted = new HashSet<Branch.NameKey>(); final Repository r = repoManager.openRepository(projectName); try { for (final Branch.NameKey branchKey : toRemove) { final String refname = branchKey.get(); final RefUpdate.Result result; final RefUpdate u; try { u = r.updateRef(refname); u.setForceUpdate(true); result = u.delete(); } catch (IOException e) { log.error("Cannot delete " + branchKey, e); continue; } switch (result) { case NEW: case NO_CHANGE: case FAST_FORWARD: case FORCED: deleted.add(branchKey); replication.scheduleUpdate(projectName, refname); hooks.doRefUpdatedHook(branchKey, u, identifiedUser.getAccount()); break; case REJECTED_CURRENT_BRANCH: log.warn("Cannot delete " + branchKey + ": " + result.name()); break; default: log.error("Cannot delete " + branchKey + ": " + result.name()); break; } } } finally { r.close(); } return deleted; }</code><technical_language>Is some sort of next() operation call instead of converting a list expensive if List of changes is large? I admit, this reads well</technical_language>

Target:
public Set<Branch.NameKey> call() throws NoSuchProjectException, RepositoryNotFoundException, OrmException { final ProjectControl projectControl = projectControlFactory.controlFor(projectName); final Iterator<Branch.NameKey> branchIt = toRemove.iterator(); while (branchIt.hasNext()) { final Branch.NameKey k = branchIt.next(); if (!projectName.equals(k.getParentKey())) { throw new IllegalArgumentException("All keys must be from same project"); } if (!projectControl.controlForRef(k).canDelete()) { throw new IllegalStateException("Cannot delete " + k.getShortName()); } if (db.changes().byBranchOpenAll(k).iterator().hasNext()) { branchIt.remove(); } } final Set<Branch.NameKey> deleted = new HashSet<Branch.NameKey>(); final Repository r = repoManager.openRepository(projectName); try { for (final Branch.NameKey branchKey : toRemove) { final String refname = branchKey.get(); final RefUpdate.Result result; final RefUpdate u; try { u = r.updateRef(refname); u.setForceUpdate(true); result = u.delete(); } catch (IOException e) { log.error("Cannot delete " + branchKey, e); continue; } switch (result) { case NEW: case NO_CHANGE: case FAST_FORWARD: case FORCED: deleted.add(branchKey); replication.scheduleUpdate(projectName, refname); hooks.doRefUpdatedHook(branchKey, u, identifiedUser.getAccount()); break; case REJECTED_CURRENT_BRANCH: log.warn("Cannot delete " + branchKey + ": " + result.name()); break; default: log.error("Cannot delete " + branchKey + ": " + result.name()); break; } } } finally { r.close(); } return deleted; }