|
15 | 15 | #include "src/__support/CPP/span.h" |
16 | 16 | #include "src/__support/libc_errno.h" // For error macros |
17 | 17 | #include "src/__support/macros/config.h" |
| 18 | +#include "src/string/memory_utils/inline_memcpy.h" |
18 | 19 |
|
19 | 20 | namespace LIBC_NAMESPACE_DECL { |
20 | 21 |
|
@@ -85,9 +86,7 @@ FileIOResult File::write_unlocked_fbf(const uint8_t *data, size_t len) { |
85 | 86 | cpp::span<uint8_t> bufref(static_cast<uint8_t *>(buf), bufsize); |
86 | 87 |
|
87 | 88 | // Copy the first piece into the buffer. |
88 | | - // TODO: Replace the for loop below with a call to internal memcpy. |
89 | | - for (size_t i = 0; i < primary.size(); ++i) |
90 | | - bufref[pos + i] = primary[i]; |
| 89 | + inline_memcpy(bufref.data() + pos, primary.data(), primary.size()); |
91 | 90 | pos += primary.size(); |
92 | 91 |
|
93 | 92 | // If there is no remainder, we can return early, since the first piece has |
@@ -115,9 +114,7 @@ FileIOResult File::write_unlocked_fbf(const uint8_t *data, size_t len) { |
115 | 114 | // know that if the second piece has data in it then the buffer has been |
116 | 115 | // flushed, meaning that pos is always 0. |
117 | 116 | if (remainder.size() < bufsize) { |
118 | | - // TODO: Replace the for loop below with a call to internal memcpy. |
119 | | - for (size_t i = 0; i < remainder.size(); ++i) |
120 | | - bufref[i] = remainder[i]; |
| 117 | + inline_memcpy(bufref.data(), remainder.data(), remainder.size()); |
121 | 118 | pos = remainder.size(); |
122 | 119 | } else { |
123 | 120 |
|
@@ -209,9 +206,7 @@ size_t File::copy_data_from_buf(uint8_t *data, size_t len) { |
209 | 206 | // available_data is never a wrapped around value. |
210 | 207 | size_t available_data = read_limit - pos; |
211 | 208 | if (len <= available_data) { |
212 | | - // TODO: Replace the for loop below with a call to internal memcpy. |
213 | | - for (size_t i = 0; i < len; ++i) |
214 | | - dataref[i] = bufref[i + pos]; |
| 209 | + inline_memcpy(dataref.data(), bufref.data() + pos, len); |
215 | 210 | pos += len; |
216 | 211 | return len; |
217 | 212 | } |
@@ -255,8 +250,7 @@ FileIOResult File::read_unlocked_fbf(uint8_t *data, size_t len) { |
255 | 250 | size_t fetched_size = result.value; |
256 | 251 | read_limit += fetched_size; |
257 | 252 | size_t transfer_size = fetched_size >= to_fetch ? to_fetch : fetched_size; |
258 | | - for (size_t i = 0; i < transfer_size; ++i) |
259 | | - dataref[i] = buf[i]; |
| 253 | + inline_memcpy(dataref.data(), buf, transfer_size); |
260 | 254 | pos += transfer_size; |
261 | 255 | if (result.has_error() || fetched_size < to_fetch) { |
262 | 256 | if (!result.has_error()) |
|
0 commit comments