diff --git a/src/word-list.c b/src/word-list.c index a88fe93ad17ccf03308151f0e214cb80093a00ea..42b993066f6ea6299d9cbf178c8d2e0e37eafa2a 100644 --- a/src/word-list.c +++ b/src/word-list.c @@ -1393,8 +1393,8 @@ word_list_find_intersection (WordList *word_list, { guint n_chars1 = 0; guint n_chars2 = 0; - g_autoptr (IpuzCharset) charset1 = NULL; - g_autoptr (IpuzCharset) charset2 = NULL; + g_autoptr (IpuzCharset) charset_incomplete = NULL; + g_autoptr (IpuzCharset) charset_complete = NULL; gboolean filter1_valid = FALSE; gboolean filter2_valid = FALSE; gunichar c1 = 0; @@ -1467,64 +1467,71 @@ word_list_find_intersection (WordList *word_list, { if (filter1_valid) { - charset1 = calculate_intersect_phase2 (word_list, - filter1, pos1, - n_chars1, - NULL, - word_array1?*word_array1:NULL); + charset_complete = + calculate_intersect_phase2 (word_list, + filter1, pos1, + n_chars1, + NULL, + word_array1?*word_array1:NULL); if (intersecting_chars) - *intersecting_chars = ipuz_charset_ref (charset1); + *intersecting_chars = ipuz_charset_ref (charset_complete); sort_word_arrays (word_array1, word_array2); } else if (filter2_valid) { - charset2 = calculate_intersect_phase2 (word_list, - filter2, pos2, - n_chars2, - NULL, - word_array2?*word_array2:NULL); + charset_complete = + calculate_intersect_phase2 (word_list, + filter2, pos2, + n_chars2, + NULL, + word_array2?*word_array2:NULL); if (intersecting_chars) - *intersecting_chars = ipuz_charset_ref (charset2); + *intersecting_chars = ipuz_charset_ref (charset_complete); sort_word_arrays (word_array1, word_array2); } - return; } /* Both filter1 and filter2 are valid, so we have to calculate the - * intersections. This is done in three phases. - */ - - /* Phase 1: Calculate the set of possible characters at pos1 for - * filter1. We don't need to worry about calculating the word_list - * yet */ - charset1 = calculate_intersect_phase1 (word_list, - filter1, pos1, - n_chars1); - - /* phase 2: Calculate the overlapping characters and the second - * word_array. If necessary, calculate the second filters word_array */ - charset2 = + * intersections. This is done in three phases. */ + + /* Phase 1: Calculate the set of possible characters at pos2 of + * the second clue, constrained by the second clue's filter. */ + charset_incomplete = calculate_intersect_phase1 (word_list, + filter2, + pos2, + n_chars2); + + /* Phase 2: Calculate the set of possible characters at pos1 of + * the first clue, constrained by the first clue's filter, and by + * charset_incomplete. If necessary, calculate word_array1. */ + charset_complete = calculate_intersect_phase2 (word_list, - filter2, pos2, - n_chars2, - charset1, - word_array2?*word_array2:NULL); - - /* phase 3: Recalculate the word_array first filter with the - * overlap */ - calculate_intersect_phase3 (word_list, - filter1, pos1, - n_chars1, - charset2, - word_array1?*word_array1:NULL); + filter1, + pos1, + n_chars1, + charset_incomplete, + word_array1?*word_array1:NULL); + + /* Phase 3 (optional): Calculate the set of possible characters at + * pos2 of the second clue, constrained by the second clue's filter, + * and by charset_complete. Calculate word_array2. */ + if (word_array2 != NULL) + { + calculate_intersect_phase3 (word_list, + filter2, + pos2, + n_chars2, + charset_complete, + *word_array2); + } sort_word_arrays (word_array1, word_array2); /* copy our charset over to intersecting_chars */ if (intersecting_chars) - *intersecting_chars = ipuz_charset_ref (charset2); + *intersecting_chars = ipuz_charset_ref (charset_complete); PUSH_TIMER ("word_list_find_intersection()"); } \ No newline at end of file