aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2024-02-10 05:00:17 -0800
committerGitHub <noreply@github.com>2024-02-10 05:00:17 -0800
commite15dfb5f79f5fddc1e5cb93a6da0e4be8aa9c506 (patch)
treee31a17200016bb045bde613ada7546bf602501cf
parent607606e3bb7a435ac5a0eba2eb4abde8eff774bb (diff)
downloadrneovim-e15dfb5f79f5fddc1e5cb93a6da0e4be8aa9c506.tar.gz
rneovim-e15dfb5f79f5fddc1e5cb93a6da0e4be8aa9c506.tar.bz2
rneovim-e15dfb5f79f5fddc1e5cb93a6da0e4be8aa9c506.zip
refactor: reduce some globals #27406
-rw-r--r--src/nvim/globals.h4
-rw-r--r--src/nvim/profile.c29
2 files changed, 15 insertions, 18 deletions
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index bcac32a252..22f7daa823 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -978,9 +978,7 @@ EXTERN const char bot_top_msg[] INIT(= N_("search hit BOTTOM, continuing at TOP"
EXTERN const char line_msg[] INIT(= N_(" line "));
-EXTERN FILE *time_fd INIT(= NULL); // where to write startup timing
-#define STARTUP_TIME_BUF_SIZE 8192
-EXTERN char *startuptime_buf INIT(= NULL); // --startuptime buffer
+EXTERN FILE *time_fd INIT(= NULL); // Where to write --startuptime report.
// Some compilers warn for not using a return value, but in some situations we
// can't do anything useful with the value. Assign to this variable to avoid
diff --git a/src/nvim/profile.c b/src/nvim/profile.c
index 84b58de4a3..b88b08d3f0 100644
--- a/src/nvim/profile.c
+++ b/src/nvim/profile.c
@@ -45,6 +45,7 @@ typedef struct {
#define PRL_ITEM(si, idx) (((sn_prl_T *)(si)->sn_prl_ga.ga_data)[(idx)])
static proftime_T prof_wait_time;
+static char *startuptime_buf = NULL; // --startuptime buffer
/// Gets the current time.
///
@@ -945,29 +946,27 @@ void time_msg(const char *mesg, const proftime_T *start)
fprintf(time_fd, ": %s\n", mesg);
}
-/// Initializes the time time_fd stream used to write startup times
+/// Initializes the `time_fd` stream for the --startuptime report.
///
-/// @param startup_time_file the startuptime report file path
-/// @param process_name the name of the current process to write in the report.
-void time_init(const char *startup_time_file, const char *process_name)
+/// @param fname startuptime report file path
+/// @param process_name name of the current Nvim process to write in the report.
+void time_init(const char *fname, const char *process_name)
{
- time_fd = fopen(startup_time_file, "a");
+ const size_t bufsize = 8192; // Big enough for the entire --startuptime report.
+ time_fd = fopen(fname, "a");
if (time_fd == NULL) {
- semsg(_(e_notopen), startup_time_file);
+ semsg(_(e_notopen), fname);
return;
}
- startuptime_buf = xmalloc(sizeof(char) * (STARTUP_TIME_BUF_SIZE + 1));
- // The startuptime file is (potentially) written by multiple nvim processes concurrently. So
- // startuptime info is buffered, and flushed to disk only after startup completed. To achieve that
- // we set a buffer big enough to store all startup times. The `_IOFBF` mode ensures the buffer is
- // not auto-flushed ("controlled buffering").
- // The times are flushed to disk manually when "time_finish" is called.
- int r = setvbuf(time_fd, startuptime_buf, _IOFBF, STARTUP_TIME_BUF_SIZE + 1);
+ startuptime_buf = xmalloc(sizeof(char) * (bufsize + 1));
+ // The startuptime file is (potentially) written by multiple Nvim processes concurrently. So each
+ // report is buffered, and flushed to disk (`time_finish`) once after startup. `_IOFBF` mode
+ // ensures the buffer is not auto-flushed ("controlled buffering").
+ int r = setvbuf(time_fd, startuptime_buf, _IOFBF, bufsize + 1);
if (r != 0) {
- xfree(startuptime_buf);
+ XFREE_CLEAR(startuptime_buf);
fclose(time_fd);
time_fd = NULL;
- // Might as well ELOG also I guess.
ELOG("time_init: setvbuf failed: %d %s", r, uv_err_name(r));
semsg("time_init: setvbuf failed: %d %s", r, uv_err_name(r));
return;