Repository: neovim/neovim
File: src/nvim/main.c (C)

Code before:

/// Initialize v:argf with the startup "file arguments".
///
/// This function collects the filenames that were passed on the command line
/// (and parsed into the global argument list by command_line_scan()) and stores
/// them in the read-only Vim variable v:argf.
///
/// Each filename is expanded to an absolute path at startup, so that v:argf
/// remains valid even if the current working directory is changed later.
///
/// Unlike v:argv, which contains the full argv vector including options
/// (-u, --cmd, +cmd, etc.), v:argf contains only the raw file arguments
/// (those appearing after options or after a `--` separator).
///
/// Unlike argv(), v:argf is not affected by later :args, :argadd, or plugin
/// modifications; it is a snapshot of the original file arguments at startup.
static void set_argf_var(void)
{
  list_T *list = tv_list_alloc(kListLenMayKnow);

  for (int i = 0; i < GARGCOUNT; i++) {
    char *fname = alist_name(&GARGLIST[i]);
    if (fname != NULL) {
      char *abs = FullName_save(fname, false);
      tv_list_append_string(list, abs != NULL ? abs : fname, -1);
      xfree(abs);
    }
  }

  tv_list_set_lock(list, VAR_FIXED);
  set_vim_var_list(VV_ARGF, list);
}

// Many variables are in "params" so that we can pass them to invoked
// functions without a lot of arguments.  "argc" and "argv" are also
// copied, so that they can be changed.
static void init_params(mparm_T *paramp, int argc, char **argv)
{
  CLEAR_POINTER(paramp);
  paramp->argc = argc;
  paramp->argv = argv;
  paramp->use_debug_break_level = -1;
  paramp->window_count = -1;
  paramp->listen_addr = NULL;
  paramp->server_addr = NULL;
  paramp->remote = 0;
  paramp->luaf = NULL;
  paramp->lua_arg0 = -1;
}

/// Initialize global startuptime file if "--startuptime" passed as an argument.

Review comment (bug):
can avoid the extra allocation by using `vim_FullName` instead of  `FullName_save`, using `NameBuff` as the buf. If it fails that means it was truncated, but that is not something we need to care about here. 4096 is enough for each `v:argf` item.

```suggestion
      (void)vim_FullName(fname, NameBuff, sizeof(NameBuff), false)
      tv_list_append_string(list, NameBuff, -1);
```

Code after:
    xfree(swcmd);
  }

  TIME_MSG("parsing arguments");
}

static void set_argf_var(void)
{
  list_T *list = tv_list_alloc(kListLenMayKnow);

  for (int i = 0; i < GARGCOUNT; i++) {
    char *fname = alist_name(&GARGLIST[i]);
    if (fname != NULL) {
      (void)vim_FullName(fname, NameBuff, sizeof(NameBuff), false);
      tv_list_append_string(list, NameBuff, -1);
    }
  }

  tv_list_set_lock(list, VAR_FIXED);
  set_vim_var_list(VV_ARGF, list);
}

// Many variables are in "params" so that we can pass them to invoked
// functions without a lot of arguments.  "argc" and "argv" are also
// copied, so that they can be changed.
static void init_params(mparm_T *paramp, int argc, char **argv)
{
  CLEAR_POINTER(paramp);
  paramp->argc = argc;
  paramp->argv = argv;
  paramp->use_debug_break_level = -1;
  paramp->window_count = -1;
  paramp->listen_addr = NULL;
  paramp->server_addr = NULL;
  paramp->remote = 0;
  paramp->luaf = NULL;
  paramp->lua_arg0 = -1;
}

/// Initialize global startuptime file if "--startuptime" passed as an argument.
static void init_startuptime(mparm_T *paramp)
{
  bool is_embed = false;
  for (int i = 1; i < paramp->argc - 1; i++) {
    if (STRICMP(paramp->argv[i], "--embed") == 0) {
      is_embed = true;
      break;
    }
  }
  for (int i = 1; i < paramp->argc - 1; i++) {
    if (STRICMP(paramp->argv[i], "--startuptime") == 0) {