Skip to content

Commit 5788bbb

Browse files
committed
ml-matches: optimize some now-dead code more
1 parent afe784a commit 5788bbb

File tree

1 file changed

+16
-35
lines changed

1 file changed

+16
-35
lines changed

src/gf.c

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,11 +2756,16 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, int offs,
27562756
}
27572757
// - it may even dominate some choices that are not subtypes!
27582758
// move those into the subtype group, where we're filter them out shortly after
2759-
// (and avoid potentially reporting these as an ambiguity)
2760-
if (!all_subtypes && minmax != NULL && !minmax_ambig) {
2759+
// (potentially avoiding reporting these as an ambiguity, and
2760+
// potentially allowing us to hit the next fast path)
2761+
// - we could always check here if *any* FULLY_COVERS method is
2762+
// more-specific (instead of just considering minmax), but that may
2763+
// cost much extra and is less likely to help us hit a fast path
2764+
// (we will look for this later, when we compute ambig_groupid, for
2765+
// correctness)
2766+
if (!all_subtypes && minmax != NULL) {
27612767
jl_method_t *minmaxm = minmax->method;
2762-
if (!include_ambiguous)
2763-
all_subtypes = 1;
2768+
all_subtypes = 1;
27642769
for (i = 0; i < len; i++) {
27652770
jl_method_match_t *matc = (jl_method_match_t*)jl_array_ptr_ref(env.t, i);
27662771
if (matc->fully_covers != FULLY_COVERS) {
@@ -2780,6 +2785,10 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, int offs,
27802785
len = 0;
27812786
env.t = jl_an_empty_vec_any;
27822787
}
2788+
else if (lim == 1) {
2789+
JL_GC_POP();
2790+
return jl_false;
2791+
}
27832792
}
27842793
else {
27852794
assert(minmax != NULL);
@@ -2798,8 +2807,8 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, int offs,
27982807
env.matc = (jl_method_match_t*)jl_array_ptr_ref(env.t, i);
27992808
jl_method_t *m = env.matc->method;
28002809
int subt = env.matc->fully_covers != NOT_FULLY_COVERS;
2801-
if ((minmax != NULL || minmax_ambig) && !include_ambiguous && subt) {
2802-
continue; // already the biggest
2810+
if ((minmax != NULL || (minmax_ambig && !include_ambiguous)) && subt) {
2811+
continue; // already the biggest (skip will filter others)
28032812
}
28042813
for (j = 0; j < i; j++) {
28052814
jl_method_match_t *matc2 = (jl_method_match_t *)jl_array_ptr_ref(env.t, i - j - 1);
@@ -2815,34 +2824,6 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, int offs,
28152824
}
28162825
jl_array_ptr_set(env.t, i - j, env.matc);
28172826
}
2818-
// final step to finish sort:
2819-
// we stopped early with just having all non-subtypes before all
2820-
// subtypes, but the case on the boundary might be wrongly placed:
2821-
// check for that now
2822-
if (minmax == NULL && !minmax_ambig) {
2823-
for (i = 0; i < len; i++) {
2824-
jl_method_match_t *matc = (jl_method_match_t*)jl_array_ptr_ref(env.t, i);
2825-
if (matc->fully_covers == FULLY_COVERS)
2826-
break;
2827-
}
2828-
for (; i > 0; i--) {
2829-
env.matc = (jl_method_match_t*)jl_array_ptr_ref(env.t, i - 1);
2830-
jl_method_t *m = env.matc->method;
2831-
for (j = i; j < len; j++) {
2832-
jl_method_match_t *matc2 = (jl_method_match_t*)jl_array_ptr_ref(env.t, j);
2833-
jl_method_t *m2 = matc2->method;
2834-
if (matc2->fully_covers != FULLY_COVERS)
2835-
break;
2836-
if (!jl_type_morespecific((jl_value_t*)m2->sig, (jl_value_t*)m->sig))
2837-
break;
2838-
jl_array_ptr_set(env.t, j - 1, matc2);
2839-
}
2840-
if (j == i)
2841-
break;
2842-
env.matc->fully_covers = SENTINEL;
2843-
jl_array_ptr_set(env.t, j - 1, env.matc);
2844-
}
2845-
}
28462827
char *skip = (char*)alloca(len);
28472828
memset(skip, 0, len);
28482829
// if we had a minmax method (any subtypes), now may now be able to
@@ -2861,7 +2842,7 @@ static jl_value_t *ml_matches(jl_methtable_t *mt, int offs,
28612842
// as we go, keep a rough count of how many methods are disjoint, which
28622843
// gives us a lower bound on how many methods we will be returning
28632844
// and lets us stop early if we reach our limit
2864-
int ndisjoint = 0;
2845+
int ndisjoint = minmax ? 1 : 0;
28652846
for (i = 0; i < len; i++) {
28662847
// can't use skip[i] here, since we still need to make sure the minmax dominates
28672848
jl_method_match_t *matc = (jl_method_match_t*)jl_array_ptr_ref(env.t, i);

0 commit comments

Comments
 (0)