Files
neovim/src/nvim/getchar.h
bfredl 77e928fd3e refactor(fileio): remove API shell layer encouraging unnecessary allocations
Functions like file_open_new() and file_open_fd_new() which just is a
wrapper around the real functions but with an extra xmalloc/xfree around
is an anti-pattern. If the caller really needs to allocate a
FileDescriptor as a heap object, it can do that directly.

FileDescriptor by itself is pretty much a pointer, or rather two:
the OS fd index and a pointer to a buffer. So most of the time an extra
pointer layer is just wasteful.

In the case of scriptin[curscript] in getchar.c, curscript used
to mean in practice:

N+1 open scripts           when curscript>0
zero or one open scripts   when curscript==0

Which means scriptin[0] had to be compared to NULL to disambiguate the
curscript=0 case.

Instead, use curscript==-1 to mean that are no script,
then all pointer comparisons dissappear and we can just use an array of
structs without extra pointers.
2024-02-25 11:20:06 +01:00

23 lines
650 B
C

#pragma once
#include <stddef.h> // IWYU pragma: keep
#include <stdint.h> // IWYU pragma: keep
#include "nvim/eval/typval_defs.h" // IWYU pragma: keep
#include "nvim/getchar_defs.h" // IWYU pragma: keep
#include "nvim/os/fileio_defs.h"
#include "nvim/types_defs.h" // IWYU pragma: keep
/// Argument for flush_buffers().
typedef enum {
FLUSH_MINIMAL,
FLUSH_TYPEAHEAD, ///< flush current typebuf contents
FLUSH_INPUT, ///< flush typebuf and inchar() input
} flush_buffers_T;
enum { NSCRIPT = 15, }; ///< Maximum number of streams to read script from
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "getchar.h.generated.h"
#endif