comparison src/quickfix.c @ 14844:a74786d0370c v8.1.0434

patch 8.1.0434: copy_loclist() is too long commit https://github.com/vim/vim/commit/09037503ea5f957ad23121bc61e15e4bb1765edf Author: Bram Moolenaar <Bram@vim.org> Date: Tue Sep 25 22:08:14 2018 +0200 patch 8.1.0434: copy_loclist() is too long Problem: copy_loclist() is too long. Solution: Split in multiple functions. (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Tue, 25 Sep 2018 22:15:06 +0200
parents 6040d93396de
children 3c8a4b25427c
comparison
equal deleted inserted replaced
14843:049e5d1f1eb0 14844:a74786d0370c
2042 wp->w_llist = ll_new_list(); /* new location list */ 2042 wp->w_llist = ll_new_list(); /* new location list */
2043 return wp->w_llist; 2043 return wp->w_llist;
2044 } 2044 }
2045 2045
2046 /* 2046 /*
2047 * Copy the location list from window "from" to window "to". 2047 * Copy location list entries from 'from_qfl' to 'to_qfl'.
2048 */
2049 static int
2050 copy_loclist_entries(qf_list_T *from_qfl, qf_list_T *to_qfl, qf_info_T *to_qi)
2051 {
2052 int i;
2053 qfline_T *from_qfp;
2054 qfline_T *prevp;
2055
2056 // copy all the location entries in this list
2057 for (i = 0, from_qfp = from_qfl->qf_start;
2058 i < from_qfl->qf_count && from_qfp != NULL;
2059 ++i, from_qfp = from_qfp->qf_next)
2060 {
2061 if (qf_add_entry(to_qi,
2062 to_qi->qf_curlist,
2063 NULL,
2064 NULL,
2065 from_qfp->qf_module,
2066 0,
2067 from_qfp->qf_text,
2068 from_qfp->qf_lnum,
2069 from_qfp->qf_col,
2070 from_qfp->qf_viscol,
2071 from_qfp->qf_pattern,
2072 from_qfp->qf_nr,
2073 0,
2074 from_qfp->qf_valid) == FAIL)
2075 return FAIL;
2076
2077 // qf_add_entry() will not set the qf_num field, as the
2078 // directory and file names are not supplied. So the qf_fnum
2079 // field is copied here.
2080 prevp = to_qfl->qf_last;
2081 prevp->qf_fnum = from_qfp->qf_fnum; // file number
2082 prevp->qf_type = from_qfp->qf_type; // error type
2083 if (from_qfl->qf_ptr == from_qfp)
2084 to_qfl->qf_ptr = prevp; // current location
2085 }
2086
2087 return OK;
2088 }
2089
2090 /*
2091 * Copy the specified location list 'from_qfl' to 'to_qfl'.
2092 */
2093 static int
2094 copy_loclist(qf_list_T *from_qfl, qf_list_T *to_qfl, qf_info_T *to_qi)
2095 {
2096 // Some of the fields are populated by qf_add_entry()
2097 to_qfl->qf_nonevalid = from_qfl->qf_nonevalid;
2098 to_qfl->qf_count = 0;
2099 to_qfl->qf_index = 0;
2100 to_qfl->qf_start = NULL;
2101 to_qfl->qf_last = NULL;
2102 to_qfl->qf_ptr = NULL;
2103 if (from_qfl->qf_title != NULL)
2104 to_qfl->qf_title = vim_strsave(from_qfl->qf_title);
2105 else
2106 to_qfl->qf_title = NULL;
2107 if (from_qfl->qf_ctx != NULL)
2108 {
2109 to_qfl->qf_ctx = alloc_tv();
2110 if (to_qfl->qf_ctx != NULL)
2111 copy_tv(from_qfl->qf_ctx, to_qfl->qf_ctx);
2112 }
2113 else
2114 to_qfl->qf_ctx = NULL;
2115
2116 if (from_qfl->qf_count)
2117 if (copy_loclist_entries(from_qfl, to_qfl, to_qi) == FAIL)
2118 return FAIL;
2119
2120 to_qfl->qf_index = from_qfl->qf_index; // current index in the list
2121
2122 // Assign a new ID for the location list
2123 to_qfl->qf_id = ++last_qf_id;
2124 to_qfl->qf_changedtick = 0L;
2125
2126 // When no valid entries are present in the list, qf_ptr points to
2127 // the first item in the list
2128 if (to_qfl->qf_nonevalid)
2129 {
2130 to_qfl->qf_ptr = to_qfl->qf_start;
2131 to_qfl->qf_index = 1;
2132 }
2133
2134 return OK;
2135 }
2136
2137 /*
2138 * Copy the location list stack 'from' window to 'to' window.
2048 */ 2139 */
2049 void 2140 void
2050 copy_loclist(win_T *from, win_T *to) 2141 copy_loclist_stack(win_T *from, win_T *to)
2051 { 2142 {
2052 qf_info_T *qi; 2143 qf_info_T *qi;
2053 int idx; 2144 int idx;
2054 int i; 2145
2055 2146 // When copying from a location list window, copy the referenced
2056 /* 2147 // location list. For other windows, copy the location list for
2057 * When copying from a location list window, copy the referenced 2148 // that window.
2058 * location list. For other windows, copy the location list for
2059 * that window.
2060 */
2061 if (IS_LL_WINDOW(from)) 2149 if (IS_LL_WINDOW(from))
2062 qi = from->w_llist_ref; 2150 qi = from->w_llist_ref;
2063 else 2151 else
2064 qi = from->w_llist; 2152 qi = from->w_llist;
2065 2153
2066 if (qi == NULL) /* no location list to copy */ 2154 if (qi == NULL) // no location list to copy
2067 return; 2155 return;
2068 2156
2069 /* allocate a new location list */ 2157 // allocate a new location list
2070 if ((to->w_llist = ll_new_list()) == NULL) 2158 if ((to->w_llist = ll_new_list()) == NULL)
2071 return; 2159 return;
2072 2160
2073 to->w_llist->qf_listcount = qi->qf_listcount; 2161 to->w_llist->qf_listcount = qi->qf_listcount;
2074 2162
2075 /* Copy the location lists one at a time */ 2163 // Copy the location lists one at a time
2076 for (idx = 0; idx < qi->qf_listcount; ++idx) 2164 for (idx = 0; idx < qi->qf_listcount; ++idx)
2077 { 2165 {
2078 qf_list_T *from_qfl;
2079 qf_list_T *to_qfl;
2080
2081 to->w_llist->qf_curlist = idx; 2166 to->w_llist->qf_curlist = idx;
2082 2167
2083 from_qfl = &qi->qf_lists[idx]; 2168 if (copy_loclist(&qi->qf_lists[idx],
2084 to_qfl = &to->w_llist->qf_lists[idx]; 2169 &to->w_llist->qf_lists[idx], to->w_llist) == FAIL)
2085 2170 {
2086 /* Some of the fields are populated by qf_add_entry() */ 2171 qf_free_all(to);
2087 to_qfl->qf_nonevalid = from_qfl->qf_nonevalid; 2172 return;
2088 to_qfl->qf_count = 0; 2173 }
2089 to_qfl->qf_index = 0; 2174 }
2090 to_qfl->qf_start = NULL; 2175
2091 to_qfl->qf_last = NULL; 2176 to->w_llist->qf_curlist = qi->qf_curlist; // current list
2092 to_qfl->qf_ptr = NULL;
2093 if (from_qfl->qf_title != NULL)
2094 to_qfl->qf_title = vim_strsave(from_qfl->qf_title);
2095 else
2096 to_qfl->qf_title = NULL;
2097 if (from_qfl->qf_ctx != NULL)
2098 {
2099 to_qfl->qf_ctx = alloc_tv();
2100 if (to_qfl->qf_ctx != NULL)
2101 copy_tv(from_qfl->qf_ctx, to_qfl->qf_ctx);
2102 }
2103 else
2104 to_qfl->qf_ctx = NULL;
2105
2106 if (from_qfl->qf_count)
2107 {
2108 qfline_T *from_qfp;
2109 qfline_T *prevp;
2110
2111 /* copy all the location entries in this list */
2112 for (i = 0, from_qfp = from_qfl->qf_start;
2113 i < from_qfl->qf_count && from_qfp != NULL;
2114 ++i, from_qfp = from_qfp->qf_next)
2115 {
2116 if (qf_add_entry(to->w_llist,
2117 to->w_llist->qf_curlist,
2118 NULL,
2119 NULL,
2120 from_qfp->qf_module,
2121 0,
2122 from_qfp->qf_text,
2123 from_qfp->qf_lnum,
2124 from_qfp->qf_col,
2125 from_qfp->qf_viscol,
2126 from_qfp->qf_pattern,
2127 from_qfp->qf_nr,
2128 0,
2129 from_qfp->qf_valid) == FAIL)
2130 {
2131 qf_free_all(to);
2132 return;
2133 }
2134 /*
2135 * qf_add_entry() will not set the qf_num field, as the
2136 * directory and file names are not supplied. So the qf_fnum
2137 * field is copied here.
2138 */
2139 prevp = to->w_llist->qf_lists[to->w_llist->qf_curlist].qf_last;
2140 prevp->qf_fnum = from_qfp->qf_fnum; /* file number */
2141 prevp->qf_type = from_qfp->qf_type; /* error type */
2142 if (from_qfl->qf_ptr == from_qfp)
2143 to_qfl->qf_ptr = prevp; /* current location */
2144 }
2145 }
2146
2147 to_qfl->qf_index = from_qfl->qf_index; /* current index in the list */
2148
2149 /* Assign a new ID for the location list */
2150 to_qfl->qf_id = ++last_qf_id;
2151 to_qfl->qf_changedtick = 0L;
2152
2153 /* When no valid entries are present in the list, qf_ptr points to
2154 * the first item in the list */
2155 if (to_qfl->qf_nonevalid)
2156 {
2157 to_qfl->qf_ptr = to_qfl->qf_start;
2158 to_qfl->qf_index = 1;
2159 }
2160 }
2161
2162 to->w_llist->qf_curlist = qi->qf_curlist; /* current list */
2163 } 2177 }
2164 2178
2165 /* 2179 /*
2166 * Get buffer number for file "directory/fname". 2180 * Get buffer number for file "directory/fname".
2167 * Also sets the b_has_qf_entry flag. 2181 * Also sets the b_has_qf_entry flag.