Skip to content

Commit e5ea95d

Browse files
committed
Revert "improve performance of lower_bound_of_target_clause (#1598)"
This reverts commit 8938331.
1 parent 8938331 commit e5ea95d

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

src/lib/builtins.pl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,6 @@
12381238
ClauseQualifier = builtins
12391239
; ClauseQualifier = Module
12401240
),
1241-
'$debug_hook',
12421241
ClauseQualifier:'$clause'(Head, Body),
12431242
'$get_clause_p'(Head, P, Module).
12441243

src/machine/compile.rs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,42 @@ pub(super) fn bootstrapping_compile(
4242
Ok(())
4343
}
4444

45-
fn lower_bound_of_target_clause(skeleton: &mut PredicateSkeleton, target_pos: usize) -> usize {
45+
fn lower_bound_of_target_clause(skeleton: &PredicateSkeleton, target_pos: usize) -> usize {
4646
if target_pos == 0 {
4747
return 0;
4848
}
4949

50-
let index = target_pos - 1;
51-
let arg_num = skeleton.clauses[index].opt_arg_index_key.arg_num();
50+
let arg_num = skeleton.clauses[target_pos - 1].opt_arg_index_key.arg_num();
5251

5352
if arg_num == 0 {
54-
return index;
53+
return target_pos - 1;
5554
}
5655

57-
skeleton
58-
.clauses[target_pos]
59-
.opt_arg_index_key
60-
.switch_on_term_loc()
61-
.map(|index_loc| {
62-
let search_result = skeleton.clauses.make_contiguous()
63-
[0 .. skeleton.core.clause_assert_margin]
64-
.partition_point(|clause_index_info| {
65-
clause_index_info.clause_start > index_loc
66-
});
67-
68-
if search_result < skeleton.core.clause_assert_margin {
69-
search_result
70-
} else {
71-
skeleton.clauses.make_contiguous()[skeleton.core.clause_assert_margin ..]
72-
.partition_point(|clause_index_info| {
73-
clause_index_info.clause_start < index_loc
74-
}) + skeleton.core.clause_assert_margin
56+
let mut index_loc_opt = None;
57+
58+
for index in (0..target_pos).rev() {
59+
let current_arg_num = skeleton.clauses[index].opt_arg_index_key.arg_num();
60+
61+
if current_arg_num == 0 || current_arg_num != arg_num {
62+
return index + 1;
63+
}
64+
65+
if let Some(index_loc) = index_loc_opt {
66+
let current_index_loc = skeleton.clauses[index]
67+
.opt_arg_index_key
68+
.switch_on_term_loc();
69+
70+
if Some(index_loc) != current_index_loc {
71+
return index + 1;
7572
}
76-
}).unwrap_or(index)
73+
} else {
74+
index_loc_opt = skeleton.clauses[index]
75+
.opt_arg_index_key
76+
.switch_on_term_loc();
77+
}
78+
}
79+
80+
0
7781
}
7882

7983
fn derelictize_try_me_else(

0 commit comments

Comments
 (0)