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

Side by Side Diff: fusl/src/locale/__mo_lookup.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 <stdint.h> 1 #include <stdint.h>
2 #include <string.h> 2 #include <string.h>
3 3
4 static inline uint32_t swapc(uint32_t x, int c) 4 static inline uint32_t swapc(uint32_t x, int c) {
5 { 5 return c ? x >> 24 | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | x << 24
6 » return c ? x>>24 | ((x>>8)&0xff00) | ((x<<8)&0xff0000) | x<<24 : x; 6 : x;
7 } 7 }
8 8
9 const char *__mo_lookup(const void *p, size_t size, const char *s) 9 const char* __mo_lookup(const void* p, size_t size, const char* s) {
10 { 10 const uint32_t* mo = p;
11 » const uint32_t *mo = p; 11 int sw = *mo - 0x950412de;
12 » int sw = *mo - 0x950412de; 12 uint32_t b = 0, n = swapc(mo[2], sw);
13 » uint32_t b = 0, n = swapc(mo[2], sw); 13 uint32_t o = swapc(mo[3], sw);
14 » uint32_t o = swapc(mo[3], sw); 14 uint32_t t = swapc(mo[4], sw);
15 » uint32_t t = swapc(mo[4], sw); 15 if (n >= size / 4 || o >= size - 4 * n || t >= size - 4 * n || ((o | t) % 4))
16 » if (n>=size/4 || o>=size-4*n || t>=size-4*n || ((o|t)%4)) 16 return 0;
17 » » return 0; 17 o /= 4;
18 » o/=4; 18 t /= 4;
19 » t/=4; 19 for (;;) {
20 » for (;;) { 20 uint32_t ol = swapc(mo[o + 2 * (b + n / 2)], sw);
21 » » uint32_t ol = swapc(mo[o+2*(b+n/2)], sw); 21 uint32_t os = swapc(mo[o + 2 * (b + n / 2) + 1], sw);
22 » » uint32_t os = swapc(mo[o+2*(b+n/2)+1], sw); 22 if (os >= size || ol >= size - os || ((char*)p)[os + ol])
23 » » if (os >= size || ol >= size-os || ((char *)p)[os+ol]) 23 return 0;
24 » » » return 0; 24 int sign = strcmp(s, (char*)p + os);
25 » » int sign = strcmp(s, (char *)p + os); 25 if (!sign) {
26 » » if (!sign) { 26 uint32_t tl = swapc(mo[t + 2 * (b + n / 2)], sw);
27 » » » uint32_t tl = swapc(mo[t+2*(b+n/2)], sw); 27 uint32_t ts = swapc(mo[t + 2 * (b + n / 2) + 1], sw);
28 » » » uint32_t ts = swapc(mo[t+2*(b+n/2)+1], sw); 28 if (ts >= size || tl >= size - ts || ((char*)p)[ts + tl])
29 » » » if (ts >= size || tl >= size-ts || ((char *)p)[ts+tl]) 29 return 0;
30 » » » » return 0; 30 return (char*)p + ts;
31 » » » return (char *)p + ts; 31 } else if (n == 1)
32 » » } 32 return 0;
33 » » else if (n == 1) return 0; 33 else if (sign < 0)
34 » » else if (sign < 0) 34 n /= 2;
35 » » » n /= 2; 35 else {
36 » » else { 36 b += n / 2;
37 » » » b += n/2; 37 n -= n / 2;
38 » » » n -= n/2; 38 }
39 » » } 39 }
40 » } 40 return 0;
41 » return 0;
42 } 41 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698