Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: fusl/src/string/memmove.c

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include <string.h> 1 #include <string.h>
2 #include <stdint.h> 2 #include <stdint.h>
3 3
4 #define WT size_t 4 #define WT size_t
5 #define WS (sizeof(WT)) 5 #define WS (sizeof(WT))
6 6
7 void *memmove(void *dest, const void *src, size_t n) 7 void* memmove(void* dest, const void* src, size_t n) {
8 { 8 char* d = dest;
9 » char *d = dest; 9 const char* s = src;
10 » const char *s = src;
11 10
12 » if (d==s) return d; 11 if (d == s)
13 » if (s+n <= d || d+n <= s) return memcpy(d, s, n); 12 return d;
13 if (s + n <= d || d + n <= s)
14 return memcpy(d, s, n);
14 15
15 » if (d<s) { 16 if (d < s) {
16 » » if ((uintptr_t)s % WS == (uintptr_t)d % WS) { 17 if ((uintptr_t)s % WS == (uintptr_t)d % WS) {
17 » » » while ((uintptr_t)d % WS) { 18 while ((uintptr_t)d % WS) {
18 » » » » if (!n--) return dest; 19 if (!n--)
19 » » » » *d++ = *s++; 20 return dest;
20 » » » } 21 *d++ = *s++;
21 » » » for (; n>=WS; n-=WS, d+=WS, s+=WS) *(WT *)d = *(WT *)s; 22 }
22 » » } 23 for (; n >= WS; n -= WS, d += WS, s += WS)
23 » » for (; n; n--) *d++ = *s++; 24 *(WT*)d = *(WT*)s;
24 » } else { 25 }
25 » » if ((uintptr_t)s % WS == (uintptr_t)d % WS) { 26 for (; n; n--)
26 » » » while ((uintptr_t)(d+n) % WS) { 27 *d++ = *s++;
27 » » » » if (!n--) return dest; 28 } else {
28 » » » » d[n] = s[n]; 29 if ((uintptr_t)s % WS == (uintptr_t)d % WS) {
29 » » » } 30 while ((uintptr_t)(d + n) % WS) {
30 » » » while (n>=WS) n-=WS, *(WT *)(d+n) = *(WT *)(s+n); 31 if (!n--)
31 » » } 32 return dest;
32 » » while (n) n--, d[n] = s[n]; 33 d[n] = s[n];
33 » } 34 }
35 while (n >= WS)
36 n -= WS, *(WT*)(d + n) = *(WT*)(s + n);
37 }
38 while (n)
39 n--, d[n] = s[n];
40 }
34 41
35 » return dest; 42 return dest;
36 } 43 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698