aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/undo.c
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-01-15 23:35:20 +0100
committerGitHub <noreply@github.com>2018-01-15 23:35:20 +0100
commitde0a9548f7bf55bdf0202a2dcebb86a92f2d989d (patch)
tree47848ab49a0188ddce9d305a187ff638ccb2965b /src/nvim/undo.c
parent726197d8907891eda99299a2920b0d1d98148a3c (diff)
parenta8cb510a2ed2f53f60ba4b2e722f4bc64954c606 (diff)
downloadrneovim-de0a9548f7bf55bdf0202a2dcebb86a92f2d989d.tar.gz
rneovim-de0a9548f7bf55bdf0202a2dcebb86a92f2d989d.tar.bz2
rneovim-de0a9548f7bf55bdf0202a2dcebb86a92f2d989d.zip
Merge #7806 from ZyX-I/list-stat
Add a way to collect list usage statistics
Diffstat (limited to 'src/nvim/undo.c')
-rw-r--r--src/nvim/undo.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index f611a3bb29..b902f82f31 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -2941,17 +2941,20 @@ bool curbufIsChanged(void)
&& (curbuf->b_changed || file_ff_differs(curbuf, true)));
}
-/*
- * For undotree(): Append the list of undo blocks at "first_uhp" to "list".
- * Recursive.
- */
-void u_eval_tree(u_header_T *first_uhp, list_T *list)
+/// Append the list of undo blocks to a newly allocated list
+///
+/// For use in undotree(). Recursive.
+///
+/// @param[in] first_uhp Undo blocks list to start with.
+///
+/// @return [allocated] List with a representation of undo blocks.
+list_T *u_eval_tree(const u_header_T *const first_uhp)
+ FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_RET
{
- u_header_T *uhp = first_uhp;
- dict_T *dict;
+ list_T *const list = tv_list_alloc(kListLenMayKnow);
- while (uhp != NULL) {
- dict = tv_dict_alloc();
+ for (const u_header_T *uhp = first_uhp; uhp != NULL; uhp = uhp->uh_prev.ptr) {
+ dict_T *const dict = tv_dict_alloc();
tv_dict_add_nr(dict, S_LEN("seq"), (varnumber_T)uhp->uh_seq);
tv_dict_add_nr(dict, S_LEN("time"), (varnumber_T)uhp->uh_time);
if (uhp == curbuf->b_u_newhead) {
@@ -2965,14 +2968,12 @@ void u_eval_tree(u_header_T *first_uhp, list_T *list)
}
if (uhp->uh_alt_next.ptr != NULL) {
- list_T *alt_list = tv_list_alloc();
-
// Recursive call to add alternate undo tree.
- u_eval_tree(uhp->uh_alt_next.ptr, alt_list);
- tv_dict_add_list(dict, S_LEN("alt"), alt_list);
+ tv_dict_add_list(dict, S_LEN("alt"), u_eval_tree(uhp->uh_alt_next.ptr));
}
tv_list_append_dict(list, dict);
- uhp = uhp->uh_prev.ptr;
}
+
+ return list;
}