diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-02-16 11:00:48 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-02-16 11:50:28 +0800 |
commit | 0cbbe27e93e87a5336673e0529b011313c51a123 (patch) | |
tree | 1a5a45358dc499a7b620c0b6b0887aafd98c8f3f /src/nvim/profile.c | |
parent | e619fb1660595f9e6a0afad8d9a91e37a94f95a3 (diff) | |
download | rneovim-0cbbe27e93e87a5336673e0529b011313c51a123.tar.gz rneovim-0cbbe27e93e87a5336673e0529b011313c51a123.tar.bz2 rneovim-0cbbe27e93e87a5336673e0529b011313c51a123.zip |
vim-patch:8.2.0154: reallocating the list of scripts is inefficient
Problem: Reallocating the list of scripts is inefficient.
Solution: Instead of using a growarray of scriptitem_T, store pointers and
allocate each scriptitem_T separately. Also avoids that the
growarray pointers change when sourcing a new script.
https://github.com/vim/vim/commit/21b9e9773d64de40994f8762173bdd8befa6acf7
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/profile.c')
-rw-r--r-- | src/nvim/profile.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/nvim/profile.c b/src/nvim/profile.c index 173332a428..6b841bd961 100644 --- a/src/nvim/profile.c +++ b/src/nvim/profile.c @@ -232,7 +232,7 @@ void profile_reset(void) { // Reset sourced files. for (int id = 1; id <= script_items.ga_len; id++) { - scriptitem_T *si = &SCRIPT_ITEM(id); + scriptitem_T *si = SCRIPT_ITEM(id); if (si->sn_prof_on) { si->sn_prof_on = false; si->sn_pr_force = false; @@ -407,7 +407,7 @@ bool prof_def_func(void) FUNC_ATTR_PURE { if (current_sctx.sc_sid > 0) { - return SCRIPT_ITEM(current_sctx.sc_sid).sn_pr_force; + return SCRIPT_ITEM(current_sctx.sc_sid)->sn_pr_force; } return false; } @@ -690,7 +690,7 @@ void profile_init(scriptitem_T *si) void script_prof_save(proftime_T *tm) { if (current_sctx.sc_sid > 0 && current_sctx.sc_sid <= script_items.ga_len) { - scriptitem_T *si = &SCRIPT_ITEM(current_sctx.sc_sid); + scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && si->sn_pr_nest++ == 0) { si->sn_pr_child = profile_start(); } @@ -705,7 +705,7 @@ void script_prof_restore(const proftime_T *tm) return; } - scriptitem_T *si = &SCRIPT_ITEM(current_sctx.sc_sid); + scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && --si->sn_pr_nest == 0) { si->sn_pr_child = profile_end(si->sn_pr_child); // don't count wait time @@ -722,7 +722,7 @@ static void script_dump_profile(FILE *fd) sn_prl_T *pp; for (int id = 1; id <= script_items.ga_len; id++) { - scriptitem_T *si = &SCRIPT_ITEM(id); + scriptitem_T *si = SCRIPT_ITEM(id); if (si->sn_prof_on) { fprintf(fd, "SCRIPT %s\n", si->sn_name); if (si->sn_pr_count == 1) { @@ -804,12 +804,10 @@ void profile_dump(void) /// until later and we need to store the time now. void script_line_start(void) { - scriptitem_T *si; - if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) { return; } - si = &SCRIPT_ITEM(current_sctx.sc_sid); + scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && SOURCING_LNUM >= 1) { // Grow the array before starting the timer, so that the time spent // here isn't counted. @@ -834,12 +832,10 @@ void script_line_start(void) /// Called when actually executing a function line. void script_line_exec(void) { - scriptitem_T *si; - if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) { return; } - si = &SCRIPT_ITEM(current_sctx.sc_sid); + scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && si->sn_prl_idx >= 0) { si->sn_prl_execed = true; } @@ -848,12 +844,10 @@ void script_line_exec(void) /// Called when done with a function line. void script_line_end(void) { - scriptitem_T *si; - if (current_sctx.sc_sid <= 0 || current_sctx.sc_sid > script_items.ga_len) { return; } - si = &SCRIPT_ITEM(current_sctx.sc_sid); + scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); if (si->sn_prof_on && si->sn_prl_idx >= 0 && si->sn_prl_idx < si->sn_prl_ga.ga_len) { if (si->sn_prl_execed) { |