]> granicus.if.org Git - vim/commitdiff
patch 8.1.0434: copy_loclist() is too long v8.1.0434
authorBram Moolenaar <Bram@vim.org>
Tue, 25 Sep 2018 20:08:14 +0000 (22:08 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 25 Sep 2018 20:08:14 +0000 (22:08 +0200)
Problem:    copy_loclist() is too long.
Solution:   Split in multiple functions. (Yegappan Lakshmanan)

src/proto/quickfix.pro
src/quickfix.c
src/version.c
src/window.c

index 26a5de0bf65fb863afc3f4c25ed9b57e2c496854..c9c3a8c96283b15a8b7ebce07001a6ca31ffb055 100644 (file)
@@ -1,7 +1,7 @@
 /* quickfix.c */
 int qf_init(win_T *wp, char_u *efile, char_u *errorformat, int newlist, char_u *qf_title, char_u *enc);
 void qf_free_all(win_T *wp);
-void copy_loclist(win_T *from, win_T *to);
+void copy_loclist_stack(win_T *from, win_T *to);
 void qf_jump(qf_info_T *qi, int dir, int errornr, int forceit);
 void qf_list(exarg_T *eap);
 void qf_age(exarg_T *eap);
index 59b3a227c8a7126b500bb1810dfb57bace73f4a8..1c3343f344d48084548c1e834fc07b7d82414c0b 100644 (file)
@@ -2044,122 +2044,136 @@ ll_get_or_alloc_list(win_T *wp)
 }
 
 /*
- * Copy the location list from window "from" to window "to".
+ * Copy location list entries from 'from_qfl' to 'to_qfl'.
+ */
+    static int
+copy_loclist_entries(qf_list_T *from_qfl, qf_list_T *to_qfl, qf_info_T *to_qi)
+{
+    int                i;
+    qfline_T    *from_qfp;
+    qfline_T    *prevp;
+
+    // copy all the location entries in this list
+    for (i = 0, from_qfp = from_qfl->qf_start;
+           i < from_qfl->qf_count && from_qfp != NULL;
+           ++i, from_qfp = from_qfp->qf_next)
+    {
+       if (qf_add_entry(to_qi,
+                   to_qi->qf_curlist,
+                   NULL,
+                   NULL,
+                   from_qfp->qf_module,
+                   0,
+                   from_qfp->qf_text,
+                   from_qfp->qf_lnum,
+                   from_qfp->qf_col,
+                   from_qfp->qf_viscol,
+                   from_qfp->qf_pattern,
+                   from_qfp->qf_nr,
+                   0,
+                   from_qfp->qf_valid) == FAIL)
+           return FAIL;
+
+       // qf_add_entry() will not set the qf_num field, as the
+       // directory and file names are not supplied. So the qf_fnum
+       // field is copied here.
+       prevp = to_qfl->qf_last;
+       prevp->qf_fnum = from_qfp->qf_fnum;     // file number
+       prevp->qf_type = from_qfp->qf_type;     // error type
+       if (from_qfl->qf_ptr == from_qfp)
+           to_qfl->qf_ptr = prevp;             // current location
+    }
+
+    return OK;
+}
+
+/*
+ * Copy the specified location list 'from_qfl' to 'to_qfl'.
+ */
+    static int
+copy_loclist(qf_list_T *from_qfl, qf_list_T *to_qfl, qf_info_T *to_qi)
+{
+    // Some of the fields are populated by qf_add_entry()
+    to_qfl->qf_nonevalid = from_qfl->qf_nonevalid;
+    to_qfl->qf_count = 0;
+    to_qfl->qf_index = 0;
+    to_qfl->qf_start = NULL;
+    to_qfl->qf_last = NULL;
+    to_qfl->qf_ptr = NULL;
+    if (from_qfl->qf_title != NULL)
+       to_qfl->qf_title = vim_strsave(from_qfl->qf_title);
+    else
+       to_qfl->qf_title = NULL;
+    if (from_qfl->qf_ctx != NULL)
+    {
+       to_qfl->qf_ctx = alloc_tv();
+       if (to_qfl->qf_ctx != NULL)
+           copy_tv(from_qfl->qf_ctx, to_qfl->qf_ctx);
+    }
+    else
+       to_qfl->qf_ctx = NULL;
+
+    if (from_qfl->qf_count)
+       if (copy_loclist_entries(from_qfl, to_qfl, to_qi) == FAIL)
+           return FAIL;
+
+    to_qfl->qf_index = from_qfl->qf_index;     // current index in the list
+
+    // Assign a new ID for the location list
+    to_qfl->qf_id = ++last_qf_id;
+    to_qfl->qf_changedtick = 0L;
+
+    // When no valid entries are present in the list, qf_ptr points to
+    // the first item in the list
+    if (to_qfl->qf_nonevalid)
+    {
+       to_qfl->qf_ptr = to_qfl->qf_start;
+       to_qfl->qf_index = 1;
+    }
+
+    return OK;
+}
+
+/*
+ * Copy the location list stack 'from' window to 'to' window.
  */
     void
-copy_loclist(win_T *from, win_T *to)
+copy_loclist_stack(win_T *from, win_T *to)
 {
     qf_info_T  *qi;
     int                idx;
-    int                i;
 
-    /*
-     * When copying from a location list window, copy the referenced
-     * location list. For other windows, copy the location list for
-     * that window.
-     */
+    // When copying from a location list window, copy the referenced
+    // location list. For other windows, copy the location list for
+    // that window.
     if (IS_LL_WINDOW(from))
        qi = from->w_llist_ref;
     else
        qi = from->w_llist;
 
-    if (qi == NULL)                /* no location list to copy */
+    if (qi == NULL)                // no location list to copy
        return;
 
-    /* allocate a new location list */
+    // allocate a new location list
     if ((to->w_llist = ll_new_list()) == NULL)
        return;
 
     to->w_llist->qf_listcount = qi->qf_listcount;
 
-    /* Copy the location lists one at a time */
+    // Copy the location lists one at a time
     for (idx = 0; idx < qi->qf_listcount; ++idx)
     {
-       qf_list_T   *from_qfl;
-       qf_list_T   *to_qfl;
-
        to->w_llist->qf_curlist = idx;
 
-       from_qfl = &qi->qf_lists[idx];
-       to_qfl = &to->w_llist->qf_lists[idx];
-
-       /* Some of the fields are populated by qf_add_entry() */
-       to_qfl->qf_nonevalid = from_qfl->qf_nonevalid;
-       to_qfl->qf_count = 0;
-       to_qfl->qf_index = 0;
-       to_qfl->qf_start = NULL;
-       to_qfl->qf_last = NULL;
-       to_qfl->qf_ptr = NULL;
-       if (from_qfl->qf_title != NULL)
-           to_qfl->qf_title = vim_strsave(from_qfl->qf_title);
-       else
-           to_qfl->qf_title = NULL;
-       if (from_qfl->qf_ctx != NULL)
-       {
-           to_qfl->qf_ctx = alloc_tv();
-           if (to_qfl->qf_ctx != NULL)
-               copy_tv(from_qfl->qf_ctx, to_qfl->qf_ctx);
-       }
-       else
-           to_qfl->qf_ctx = NULL;
-
-       if (from_qfl->qf_count)
+       if (copy_loclist(&qi->qf_lists[idx],
+                       &to->w_llist->qf_lists[idx], to->w_llist) == FAIL)
        {
-           qfline_T    *from_qfp;
-           qfline_T    *prevp;
-
-           /* copy all the location entries in this list */
-           for (i = 0, from_qfp = from_qfl->qf_start;
-                   i < from_qfl->qf_count && from_qfp != NULL;
-                   ++i, from_qfp = from_qfp->qf_next)
-           {
-               if (qf_add_entry(to->w_llist,
-                                to->w_llist->qf_curlist,
-                                NULL,
-                                NULL,
-                                from_qfp->qf_module,
-                                0,
-                                from_qfp->qf_text,
-                                from_qfp->qf_lnum,
-                                from_qfp->qf_col,
-                                from_qfp->qf_viscol,
-                                from_qfp->qf_pattern,
-                                from_qfp->qf_nr,
-                                0,
-                                from_qfp->qf_valid) == FAIL)
-               {
-                   qf_free_all(to);
-                   return;
-               }
-               /*
-                * qf_add_entry() will not set the qf_num field, as the
-                * directory and file names are not supplied. So the qf_fnum
-                * field is copied here.
-                */
-               prevp = to->w_llist->qf_lists[to->w_llist->qf_curlist].qf_last;
-               prevp->qf_fnum = from_qfp->qf_fnum; /* file number */
-               prevp->qf_type = from_qfp->qf_type; /* error type */
-               if (from_qfl->qf_ptr == from_qfp)
-                   to_qfl->qf_ptr = prevp;         /* current location */
-           }
-       }
-
-       to_qfl->qf_index = from_qfl->qf_index;  /* current index in the list */
-
-       /* Assign a new ID for the location list */
-       to_qfl->qf_id = ++last_qf_id;
-       to_qfl->qf_changedtick = 0L;
-
-       /* When no valid entries are present in the list, qf_ptr points to
-        * the first item in the list */
-       if (to_qfl->qf_nonevalid)
-       {
-           to_qfl->qf_ptr = to_qfl->qf_start;
-           to_qfl->qf_index = 1;
+           qf_free_all(to);
+           return;
        }
     }
 
-    to->w_llist->qf_curlist = qi->qf_curlist;  /* current list */
+    to->w_llist->qf_curlist = qi->qf_curlist;  // current list
 }
 
 /*
index 6c69b17d696414724d0cd808c18405b838fbe264..73eff7d6b5a80f2643a1328963f2bc0cedb0dbf3 100644 (file)
@@ -794,6 +794,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    434,
 /**/
     433,
 /**/
index a481af8b95f89bd3965ebaf99c053ecda3e2d0f0..b50d835e4628ae9f04aed22a1627eff5c457532b 100644 (file)
@@ -1308,7 +1308,7 @@ win_init(win_T *newp, win_T *oldp, int flags UNUSED)
        newp->w_llist_ref = NULL;
     }
     else
-       copy_loclist(oldp, newp);
+       copy_loclist_stack(oldp, newp);
 #endif
     newp->w_localdir = (oldp->w_localdir == NULL)
                                    ? NULL : vim_strsave(oldp->w_localdir);