Remove unnecessary Prolog-to-Java conversion from submit filters
Instead of converting intermediate filtering results from Prolog to Java (and back) in each filtering iteration, perform the conversion only after the last submit filter is done. Also change the return type of the SubmitRuleEvaluator.evaluate to return ListTerm and let the caller decide how to convert it to a Java list. This is necessary because the ListTerm.toJava method can produce either List<Term> or List<String> as its result depending on what is contained in the ListTerm instance. Change-Id: I70ca979785c766653281994dd3097fc8795e1a87 Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
This commit is contained in:
committed by
Gerrit Code Review
parent
3531ca4b8f
commit
162c801f4b
@@ -297,6 +297,7 @@ public class ChangeControl {
|
||||
return canSubmit(db, patchSet, null, false, false);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<SubmitRecord> canSubmit(ReviewDb db, PatchSet patchSet,
|
||||
@Nullable ChangeData cd, boolean fastEvalLabels, boolean allowClosed) {
|
||||
if (!allowClosed && change.getStatus().isClosed()) {
|
||||
@@ -337,7 +338,7 @@ public class ChangeControl {
|
||||
fastEvalLabels,
|
||||
"locate_submit_rule", "can_submit",
|
||||
"locate_submit_filter", "filter_submit_results");
|
||||
results = evaluator.evaluate();
|
||||
results = evaluator.evaluate().toJava();
|
||||
} catch (RuleEvalException e) {
|
||||
return logRuleError(e.getMessage(), e);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class SubmitRuleEvaluator {
|
||||
* @return List of {@link Term} objects returned from the evaluated rules.
|
||||
* @throws RuleEvalException
|
||||
*/
|
||||
List<Term> evaluate() throws RuleEvalException {
|
||||
ListTerm evaluate() throws RuleEvalException {
|
||||
List<Term> results = new ArrayList<Term>();
|
||||
ProjectState projectState = projectControl.getProjectState();
|
||||
PrologEnvironment env;
|
||||
@@ -140,6 +140,7 @@ public class SubmitRuleEvaluator {
|
||||
Set<Project.NameKey> projectsSeen = new HashSet<Project.NameKey>();
|
||||
projectsSeen.add(projectState.getProject().getNameKey());
|
||||
|
||||
Term resultsTerm = toListTerm(results);
|
||||
while (parentState != null) {
|
||||
if (!projectsSeen.add(parentState.getProject().getNameKey())) {
|
||||
// parent has been seen before, stop walk up inheritance tree
|
||||
@@ -161,15 +162,10 @@ public class SubmitRuleEvaluator {
|
||||
env.once("gerrit", "assume_range_from_label");
|
||||
}
|
||||
|
||||
Term resultsTerm = toListTerm(results);
|
||||
results.clear();
|
||||
Term[] template =
|
||||
parentEnv.once("gerrit", filterRuleWrapperName, filterRule,
|
||||
resultsTerm, new VariableTerm());
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<? extends Term> termList =
|
||||
((ListTerm) template[2]).toJava();
|
||||
results.addAll(termList);
|
||||
resultsTerm = template[2];
|
||||
} catch (PrologException err) {
|
||||
throw new RuleEvalException("Exception calling " + filterRule
|
||||
+ " on change " + change.getId() + " of "
|
||||
@@ -183,11 +179,11 @@ public class SubmitRuleEvaluator {
|
||||
parentState = parentState.getParentState();
|
||||
childEnv = parentEnv;
|
||||
}
|
||||
|
||||
return (ListTerm) resultsTerm;
|
||||
} finally {
|
||||
env.close();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
private static Term toListTerm(List<Term> terms) {
|
||||
|
||||
Reference in New Issue
Block a user