Skip to content

Commit 0903750

Browse files
committed
patch 8.1.0434: copy_loclist() is too long
Problem: copy_loclist() is too long. Solution: Split in multiple functions. (Yegappan Lakshmanan)
1 parent 31cbadf commit 0903750

4 files changed

Lines changed: 108 additions & 92 deletions

File tree

src/proto/quickfix.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* quickfix.c */
22
int qf_init(win_T *wp, char_u *efile, char_u *errorformat, int newlist, char_u *qf_title, char_u *enc);
33
void qf_free_all(win_T *wp);
4-
void copy_loclist(win_T *from, win_T *to);
4+
void copy_loclist_stack(win_T *from, win_T *to);
55
void qf_jump(qf_info_T *qi, int dir, int errornr, int forceit);
66
void qf_list(exarg_T *eap);
77
void qf_age(exarg_T *eap);

src/quickfix.c

Lines changed: 104 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,122 +2044,136 @@ ll_get_or_alloc_list(win_T *wp)
20442044
}
20452045

20462046
/*
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.
20482139
*/
20492140
void
2050-
copy_loclist(win_T *from, win_T *to)
2141+
copy_loclist_stack(win_T *from, win_T *to)
20512142
{
20522143
qf_info_T *qi;
20532144
int idx;
2054-
int i;
20552145

2056-
/*
2057-
* When copying from a location list window, copy the referenced
2058-
* location list. For other windows, copy the location list for
2059-
* that window.
2060-
*/
2146+
// When copying from a location list window, copy the referenced
2147+
// location list. For other windows, copy the location list for
2148+
// that window.
20612149
if (IS_LL_WINDOW(from))
20622150
qi = from->w_llist_ref;
20632151
else
20642152
qi = from->w_llist;
20652153

2066-
if (qi == NULL) /* no location list to copy */
2154+
if (qi == NULL) // no location list to copy
20672155
return;
20682156

2069-
/* allocate a new location list */
2157+
// allocate a new location list
20702158
if ((to->w_llist = ll_new_list()) == NULL)
20712159
return;
20722160

20732161
to->w_llist->qf_listcount = qi->qf_listcount;
20742162

2075-
/* Copy the location lists one at a time */
2163+
// Copy the location lists one at a time
20762164
for (idx = 0; idx < qi->qf_listcount; ++idx)
20772165
{
2078-
qf_list_T *from_qfl;
2079-
qf_list_T *to_qfl;
2080-
20812166
to->w_llist->qf_curlist = idx;
20822167

2083-
from_qfl = &qi->qf_lists[idx];
2084-
to_qfl = &to->w_llist->qf_lists[idx];
2085-
2086-
/* Some of the fields are populated by qf_add_entry() */
2087-
to_qfl->qf_nonevalid = from_qfl->qf_nonevalid;
2088-
to_qfl->qf_count = 0;
2089-
to_qfl->qf_index = 0;
2090-
to_qfl->qf_start = NULL;
2091-
to_qfl->qf_last = NULL;
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)
2168+
if (copy_loclist(&qi->qf_lists[idx],
2169+
&to->w_llist->qf_lists[idx], to->w_llist) == FAIL)
21072170
{
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;
2171+
qf_free_all(to);
2172+
return;
21592173
}
21602174
}
21612175

2162-
to->w_llist->qf_curlist = qi->qf_curlist; /* current list */
2176+
to->w_llist->qf_curlist = qi->qf_curlist; // current list
21632177
}
21642178

21652179
/*

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,8 @@ static char *(features[]) =
794794

795795
static int included_patches[] =
796796
{ /* Add new patch number below this line */
797+
/**/
798+
434,
797799
/**/
798800
433,
799801
/**/

src/window.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ win_init(win_T *newp, win_T *oldp, int flags UNUSED)
13081308
newp->w_llist_ref = NULL;
13091309
}
13101310
else
1311-
copy_loclist(oldp, newp);
1311+
copy_loclist_stack(oldp, newp);
13121312
#endif
13131313
newp->w_localdir = (oldp->w_localdir == NULL)
13141314
? NULL : vim_strsave(oldp->w_localdir);

0 commit comments

Comments
 (0)