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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: fusl/src/locale/__mo_lookup.c
diff --git a/fusl/src/locale/__mo_lookup.c b/fusl/src/locale/__mo_lookup.c
index e821e1253a268a94143f209b6d7fec48d0d3001e..21b4c73491ae209f327fb4d43502c4e61c074789 100644
--- a/fusl/src/locale/__mo_lookup.c
+++ b/fusl/src/locale/__mo_lookup.c
@@ -1,42 +1,41 @@
#include <stdint.h>
#include <string.h>
-static inline uint32_t swapc(uint32_t x, int c)
-{
- return c ? x>>24 | ((x>>8)&0xff00) | ((x<<8)&0xff0000) | x<<24 : x;
+static inline uint32_t swapc(uint32_t x, int c) {
+ return c ? x >> 24 | ((x >> 8) & 0xff00) | ((x << 8) & 0xff0000) | x << 24
+ : x;
}
-const char *__mo_lookup(const void *p, size_t size, const char *s)
-{
- const uint32_t *mo = p;
- int sw = *mo - 0x950412de;
- uint32_t b = 0, n = swapc(mo[2], sw);
- uint32_t o = swapc(mo[3], sw);
- uint32_t t = swapc(mo[4], sw);
- if (n>=size/4 || o>=size-4*n || t>=size-4*n || ((o|t)%4))
- return 0;
- o/=4;
- t/=4;
- for (;;) {
- uint32_t ol = swapc(mo[o+2*(b+n/2)], sw);
- uint32_t os = swapc(mo[o+2*(b+n/2)+1], sw);
- if (os >= size || ol >= size-os || ((char *)p)[os+ol])
- return 0;
- int sign = strcmp(s, (char *)p + os);
- if (!sign) {
- uint32_t tl = swapc(mo[t+2*(b+n/2)], sw);
- uint32_t ts = swapc(mo[t+2*(b+n/2)+1], sw);
- if (ts >= size || tl >= size-ts || ((char *)p)[ts+tl])
- return 0;
- return (char *)p + ts;
- }
- else if (n == 1) return 0;
- else if (sign < 0)
- n /= 2;
- else {
- b += n/2;
- n -= n/2;
- }
- }
- return 0;
+const char* __mo_lookup(const void* p, size_t size, const char* s) {
+ const uint32_t* mo = p;
+ int sw = *mo - 0x950412de;
+ uint32_t b = 0, n = swapc(mo[2], sw);
+ uint32_t o = swapc(mo[3], sw);
+ uint32_t t = swapc(mo[4], sw);
+ if (n >= size / 4 || o >= size - 4 * n || t >= size - 4 * n || ((o | t) % 4))
+ return 0;
+ o /= 4;
+ t /= 4;
+ for (;;) {
+ uint32_t ol = swapc(mo[o + 2 * (b + n / 2)], sw);
+ uint32_t os = swapc(mo[o + 2 * (b + n / 2) + 1], sw);
+ if (os >= size || ol >= size - os || ((char*)p)[os + ol])
+ return 0;
+ int sign = strcmp(s, (char*)p + os);
+ if (!sign) {
+ uint32_t tl = swapc(mo[t + 2 * (b + n / 2)], sw);
+ uint32_t ts = swapc(mo[t + 2 * (b + n / 2) + 1], sw);
+ if (ts >= size || tl >= size - ts || ((char*)p)[ts + tl])
+ return 0;
+ return (char*)p + ts;
+ } else if (n == 1)
+ return 0;
+ else if (sign < 0)
+ n /= 2;
+ else {
+ b += n / 2;
+ n -= n / 2;
+ }
+ }
+ return 0;
}

Powered by Google App Engine
This is Rietveld 408576698