|
15 | 15 |
|
16 | 16 | namespace __llvm_libc {
|
17 | 17 |
|
18 |
| -static inline void move_byte_forward(char *dest_m, const char *src_m, |
19 |
| - size_t count) { |
20 |
| - for (size_t offset = 0; count; --count, ++offset) |
| 18 | +static inline void move_byte_forward(unsigned char *dest_m, |
| 19 | + const unsigned char *src_m, |
| 20 | + size_t count) noexcept { |
| 21 | + for (size_t offset = 0; offset != count; ++offset) |
21 | 22 | dest_m[offset] = src_m[offset];
|
22 | 23 | }
|
23 | 24 |
|
24 |
| -static inline void move_byte_backward(char *dest_m, const char *src_m, |
25 |
| - size_t count) { |
26 |
| - for (size_t offset = count - 1; count; --count, --offset) |
27 |
| - dest_m[offset] = src_m[offset]; |
| 25 | +static inline void move_byte_backward(unsigned char *dest_m, |
| 26 | + const unsigned char *src_m, |
| 27 | + size_t count) noexcept { |
| 28 | + for (size_t offset = count; offset != 0; --offset) |
| 29 | + dest_m[offset - 1] = src_m[offset - 1]; |
28 | 30 | }
|
29 | 31 |
|
30 |
| -LLVM_LIBC_FUNCTION(void *, memmove, |
31 |
| - (void *dest, const void *src, size_t count)) { |
32 |
| - char *dest_c = reinterpret_cast<char *>(dest); |
33 |
| - const char *src_c = reinterpret_cast<const char *>(src); |
| 32 | +LLVM_LIBC_FUNCTION(void *, memmove, (void *dest, const void *src, size_t count)) |
| 33 | +noexcept { |
| 34 | + unsigned char *dest_c = reinterpret_cast<unsigned char *>(dest); |
| 35 | + const unsigned char *src_c = reinterpret_cast<const unsigned char *>(src); |
34 | 36 |
|
35 | 37 | // If the distance between src_c and dest_c is equal to or greater
|
36 | 38 | // than count (integerAbs(src_c - dest_c) >= count), they would not overlap.
|
@@ -58,7 +60,7 @@ LLVM_LIBC_FUNCTION(void *, memmove,
|
58 | 60 | // TODO: Optimize `move_byte_xxx(...)` functions.
|
59 | 61 | if (dest_c < src_c)
|
60 | 62 | move_byte_forward(dest_c, src_c, count);
|
61 |
| - if (dest_c > src_c) |
| 63 | + else if (dest_c > src_c) |
62 | 64 | move_byte_backward(dest_c, src_c, count);
|
63 | 65 | return dest;
|
64 | 66 | }
|
|
0 commit comments