aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/os
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2024-06-08 14:19:30 +0200
committerbfredl <bjorn.linse@gmail.com>2024-06-11 11:11:38 +0200
commit19052e0a06240be018a234d87f51113eca6d17fa (patch)
treeda5d0eb9c4bcb26d7947d9708cd2d4676f7a1fa5 /src/nvim/os
parentd8e384b7bfd5829e5ff5006202faa584b3211e84 (diff)
downloadrneovim-19052e0a06240be018a234d87f51113eca6d17fa.tar.gz
rneovim-19052e0a06240be018a234d87f51113eca6d17fa.tar.bz2
rneovim-19052e0a06240be018a234d87f51113eca6d17fa.zip
refactor(shada): use msgpack_sbuffer less
Work towards getting rid of libmsgpack depedency eventually. msgpack_sbuffer is just a string buffer, we can use our own String type.
Diffstat (limited to 'src/nvim/os')
-rw-r--r--src/nvim/os/fileio.c3
-rw-r--r--src/nvim/os/fileio.h6
2 files changed, 7 insertions, 2 deletions
diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c
index 585c4964e2..89834bed80 100644
--- a/src/nvim/os/fileio.c
+++ b/src/nvim/os/fileio.c
@@ -320,9 +320,8 @@ ptrdiff_t file_write(FileDescriptor *const fp, const char *const buf, const size
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ARG(1)
{
assert(fp->wr);
- ptrdiff_t space = (fp->buffer + ARENA_BLOCK_SIZE) - fp->write_pos;
// includes the trivial case of size==0
- if (size < (size_t)space) {
+ if (size < file_space(fp)) {
memcpy(fp->write_pos, buf, size);
fp->write_pos += size;
return (ptrdiff_t)size;
diff --git a/src/nvim/os/fileio.h b/src/nvim/os/fileio.h
index e8fd2209db..523f9657a4 100644
--- a/src/nvim/os/fileio.h
+++ b/src/nvim/os/fileio.h
@@ -2,6 +2,7 @@
#include <stddef.h> // IWYU pragma: keep
+#include "nvim/memory_defs.h"
#include "nvim/os/fileio_defs.h" // IWYU pragma: keep
/// file_open() flags
@@ -32,6 +33,11 @@ enum {
kRWBufferSize = 1024,
};
+static inline size_t file_space(FileDescriptor *fp)
+{
+ return (size_t)((fp->buffer + ARENA_BLOCK_SIZE) - fp->write_pos);
+}
+
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "os/fileio.h.generated.h"
#endif