[libc-commits] [PATCH] D126829: [libc] add buffering to FILE writes
Michael Jones via Phabricator via libc-commits
libc-commits at lists.llvm.org
Thu Jun 9 14:06:11 PDT 2022
michaelrj added inline comments.
================
Comment at: libc/src/__support/File/file.cpp:141
+
+ // If the primary piece fits in the buffer, copy the it into the buffer.
+ if (primary.size() <= bufspace) {
----------------
sivachandra wrote:
> We will keep the implementation simple for now like this:
>
> ```
> fbf(primary.data(), primary.size());
> // Error check
> flush_unlocked(); // A call to flush and not to platform_flush()
> fbf(remaining.data(), remaining.size());
> // Error check
> ```
>
> It should incur the same number of `platform_*` calls but might lead to a few additional copies. Iff required, we can optimize FBF to eliminate the unecessary copies. Infact, what we really want is to replace the first FBF operation by an NBF operation. We can do all that iff required.
>
> I don't think we have `flush_unlocked`, so you will have to add it.
I did add NBF as well as `flush_unlocked`, and now we're down to three platform writes maximum (one for the buffer, one for the section up to the newline, and one for the remainder).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126829/new/
https://reviews.llvm.org/D126829
More information about the libc-commits
mailing list