From: notoria Date: Mon, 21 Dec 2020 19:05:45 +0000 (+0100) Subject: Renamed find_optimal_index to first_instantiated_index X-Git-Tag: v0.9.0~166^2 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=706d842102b0dedf6b3aab8080dcb262e208811a;p=scryer-prolog.git Renamed find_optimal_index to first_instantiated_index --- diff --git a/src/codegen.rs b/src/codegen.rs index 7b328e7e..d260cfa0 100644 --- a/src/codegen.rs +++ b/src/codegen.rs @@ -858,7 +858,8 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator { Ok(code) } - fn find_optimal_index(clauses: &[PredicateClause]) -> usize { + /// Returns the index of the first instantiated argument. + fn first_instantiated_index(clauses: &[PredicateClause]) -> Option { let mut optimal_index = None; let has_args = match clauses.first() { Some(clause) => match clause.args() { @@ -868,7 +869,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator { None => false, }; if !has_args { - return 0; + return optimal_index; } for clause in clauses.iter() { let args = clause.args().unwrap(); @@ -890,10 +891,8 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator { } } } - match optimal_index { - Some(optimal_index) => optimal_index, - None => 0, // Default to first argument indexing. - } + + optimal_index } fn split_predicate(clauses: &[PredicateClause], optimal_index: usize) -> Vec<(usize, usize)> { @@ -996,7 +995,10 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator { clauses: &'b Vec, ) -> Result { let mut code = Vec::new(); - let optimal_index = Self::find_optimal_index(&clauses); + let optimal_index = match Self::first_instantiated_index(&clauses) { + Some(index) => index, + None => 0, // Default to first argument indexing. + }; let split_pred = Self::split_predicate(&clauses, optimal_index); let multi_seq = split_pred.len() > 1;