From 706d842102b0dedf6b3aab8080dcb262e208811a Mon Sep 17 00:00:00 2001 From: notoria Date: Mon, 21 Dec 2020 20:05:45 +0100 Subject: [PATCH] Renamed find_optimal_index to first_instantiated_index --- src/codegen.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) 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; -- 2.54.0