diff options
author | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-04-10 01:04:37 +0000 |
---|---|---|
committer | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-04-10 01:04:37 +0000 |
commit | 4e1d3acc16edb0b502cff157978235f5af627a5a (patch) | |
tree | 1df757df2590777d5eb4a07bb616a4fa8e07c8ba /src/core/SkUtils.cpp | |
parent | d5e05d428647c164080e38dabee94db52c8c4544 (diff) |
code style
git-svn-id: http://skia.googlecode.com/svn/trunk@1095 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkUtils.cpp')
-rw-r--r-- | src/core/SkUtils.cpp | 195 |
1 files changed, 78 insertions, 117 deletions
diff --git a/src/core/SkUtils.cpp b/src/core/SkUtils.cpp index 9fb85c2939..6aa57eeaac 100644 --- a/src/core/SkUtils.cpp +++ b/src/core/SkUtils.cpp @@ -43,18 +43,17 @@ } while (0) #endif -/////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// -void sk_memset16_portable(uint16_t dst[], uint16_t value, int count) -{ +void sk_memset16_portable(uint16_t dst[], uint16_t value, int count) { SkASSERT(dst != NULL && count >= 0); - if (count <= 0) + if (count <= 0) { return; + } // not sure if this helps to short-circuit on small values of count - if (count < 8) - { + if (count < 8) { do { *dst++ = (uint16_t)value; } while (--count != 0); @@ -62,8 +61,7 @@ void sk_memset16_portable(uint16_t dst[], uint16_t value, int count) } // ensure we're on a long boundary - if ((size_t)dst & 2) - { + if ((size_t)dst & 2) { *dst++ = (uint16_t)value; count -= 1; } @@ -73,8 +71,7 @@ void sk_memset16_portable(uint16_t dst[], uint16_t value, int count) // handle the bulk with our unrolled macro { int sixteenlongs = count >> 5; - if (sixteenlongs) - { + if (sixteenlongs) { uint32_t* dst32 = (uint32_t*)dst; do { assign_16_longs(dst32, value32); @@ -87,8 +84,7 @@ void sk_memset16_portable(uint16_t dst[], uint16_t value, int count) // handle (most) of the rest { int longs = count >> 1; - if (longs) - { + if (longs) { do { *(uint32_t*)dst = value32; dst += 2; @@ -97,27 +93,23 @@ void sk_memset16_portable(uint16_t dst[], uint16_t value, int count) } // cleanup a possible trailing short - if (count & 1) + if (count & 1) { *dst = (uint16_t)value; + } } -void sk_memset32_portable(uint32_t dst[], uint32_t value, int count) -{ +void sk_memset32_portable(uint32_t dst[], uint32_t value, int count) { SkASSERT(dst != NULL && count >= 0); - { - int sixteenlongs = count >> 4; - if (sixteenlongs) - { - do { - assign_16_longs(dst, value); - } while (--sixteenlongs != 0); - count &= 15; - } + int sixteenlongs = count >> 4; + if (sixteenlongs) { + do { + assign_16_longs(dst, value); + } while (--sixteenlongs != 0); + count &= 15; } - if (count) - { + if (count) { do { *dst++ = value; } while (--count != 0); @@ -125,8 +117,7 @@ void sk_memset32_portable(uint32_t dst[], uint32_t value, int count) } #if !defined(ANDROID) || defined(SK_BUILD_FOR_ANDROID_NDK) -static void sk_memset16_stub(uint16_t dst[], uint16_t value, int count) -{ +static void sk_memset16_stub(uint16_t dst[], uint16_t value, int count) { SkMemset16Proc proc = SkMemset16GetPlatformProc(); sk_memset16 = proc ? proc : sk_memset16_portable; sk_memset16(dst, value, count); @@ -134,8 +125,7 @@ static void sk_memset16_stub(uint16_t dst[], uint16_t value, int count) SkMemset16Proc sk_memset16 = sk_memset16_stub; -static void sk_memset32_stub(uint32_t dst[], uint32_t value, int count) -{ +static void sk_memset32_stub(uint32_t dst[], uint32_t value, int count) { SkMemset32Proc proc = SkMemset32GetPlatformProc(); sk_memset32 = proc ? proc : sk_memset32_portable; sk_memset32(dst, value, count); @@ -145,7 +135,7 @@ SkMemset32Proc sk_memset32 = sk_memset32_stub; #endif -////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// /* 0xxxxxxx 1 total 10xxxxxx // never a leading byte @@ -159,14 +149,12 @@ SkMemset32Proc sk_memset32 = sk_memset32_stub; */ #ifdef SK_DEBUG - static void assert_utf8_leadingbyte(unsigned c) - { + static void assert_utf8_leadingbyte(unsigned c) { SkASSERT(c <= 0xF7); // otherwise leading byte is too big (more than 4 bytes) SkASSERT((c & 0xC0) != 0x80); // can't begin with a middle char } - int SkUTF8_LeadByteToCount(unsigned c) - { + int SkUTF8_LeadByteToCount(unsigned c) { assert_utf8_leadingbyte(c); return (((0xE5 << 24) >> (c >> 4 << 1)) & 3) + 1; } @@ -174,41 +162,36 @@ SkMemset32Proc sk_memset32 = sk_memset32_stub; #define assert_utf8_leadingbyte(c) #endif -int SkUTF8_CountUnichars(const char utf8[]) -{ +int SkUTF8_CountUnichars(const char utf8[]) { SkASSERT(utf8); int count = 0; - for (;;) - { + for (;;) { int c = *(const uint8_t*)utf8; - if (c == 0) + if (c == 0) { break; - + } utf8 += SkUTF8_LeadByteToCount(c); count += 1; } return count; } -int SkUTF8_CountUnichars(const char utf8[], size_t byteLength) -{ +int SkUTF8_CountUnichars(const char utf8[], size_t byteLength) { SkASSERT(NULL != utf8 || 0 == byteLength); int count = 0; const char* stop = utf8 + byteLength; - while (utf8 < stop) - { + while (utf8 < stop) { utf8 += SkUTF8_LeadByteToCount(*(const uint8_t*)utf8); count += 1; } return count; } -SkUnichar SkUTF8_ToUnichar(const char utf8[]) -{ +SkUnichar SkUTF8_ToUnichar(const char utf8[]) { SkASSERT(NULL != utf8); const uint8_t* p = (const uint8_t*)utf8; @@ -217,8 +200,7 @@ SkUnichar SkUTF8_ToUnichar(const char utf8[]) assert_utf8_leadingbyte(c); - if (hic < 0) - { + if (hic < 0) { uint32_t mask = (uint32_t)~0x3F; hic <<= 1; do { @@ -230,8 +212,7 @@ SkUnichar SkUTF8_ToUnichar(const char utf8[]) return c; } -SkUnichar SkUTF8_NextUnichar(const char** ptr) -{ +SkUnichar SkUTF8_NextUnichar(const char** ptr) { SkASSERT(NULL != ptr && NULL != *ptr); const uint8_t* p = (const uint8_t*)*ptr; @@ -240,8 +221,7 @@ SkUnichar SkUTF8_NextUnichar(const char** ptr) assert_utf8_leadingbyte(c); - if (hic < 0) - { + if (hic < 0) { uint32_t mask = (uint32_t)~0x3F; hic <<= 1; do { @@ -254,32 +234,31 @@ SkUnichar SkUTF8_NextUnichar(const char** ptr) return c; } -SkUnichar SkUTF8_PrevUnichar(const char** ptr) -{ +SkUnichar SkUTF8_PrevUnichar(const char** ptr) { SkASSERT(NULL != ptr && NULL != *ptr); const char* p = *ptr; - if (*--p & 0x80) - while (*--p & 0x40) + if (*--p & 0x80) { + while (*--p & 0x40) { ; + } + } *ptr = (char*)p; return SkUTF8_NextUnichar(&p); } -size_t SkUTF8_FromUnichar(SkUnichar uni, char utf8[]) -{ - if ((uint32_t)uni > 0x10FFFF) - { +size_t SkUTF8_FromUnichar(SkUnichar uni, char utf8[]) { + if ((uint32_t)uni > 0x10FFFF) { SkASSERT(!"bad unichar"); return 0; } - if (uni <= 127) - { - if (utf8) + if (uni <= 127) { + if (utf8) { *utf8 = (char)uni; + } return 1; } @@ -289,19 +268,18 @@ size_t SkUTF8_FromUnichar(SkUnichar uni, char utf8[]) SkDEBUGCODE(SkUnichar orig = uni;) - while (uni > 0x7F >> count) - { + while (uni > 0x7F >> count) { *p++ = (char)(0x80 | (uni & 0x3F)); uni >>= 6; count += 1; } - if (utf8) - { + if (utf8) { p = tmp; utf8 += count; - while (p < tmp + count - 1) + while (p < tmp + count - 1) { *--utf8 = *p++; + } *--utf8 = (char)(~(0xFF >> count) | uni); } @@ -309,19 +287,16 @@ size_t SkUTF8_FromUnichar(SkUnichar uni, char utf8[]) return count; } -//////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// -int SkUTF16_CountUnichars(const uint16_t src[]) -{ +int SkUTF16_CountUnichars(const uint16_t src[]) { SkASSERT(src); int count = 0; unsigned c; - while ((c = *src++) != 0) - { + while ((c = *src++) != 0) { SkASSERT(!SkUTF16_IsLowSurrogate(c)); - if (SkUTF16_IsHighSurrogate(c)) - { + if (SkUTF16_IsHighSurrogate(c)) { c = *src++; SkASSERT(SkUTF16_IsLowSurrogate(c)); } @@ -330,18 +305,15 @@ int SkUTF16_CountUnichars(const uint16_t src[]) return count; } -int SkUTF16_CountUnichars(const uint16_t src[], int numberOf16BitValues) -{ +int SkUTF16_CountUnichars(const uint16_t src[], int numberOf16BitValues) { SkASSERT(src); const uint16_t* stop = src + numberOf16BitValues; int count = 0; - while (src < stop) - { + while (src < stop) { unsigned c = *src++; SkASSERT(!SkUTF16_IsLowSurrogate(c)); - if (SkUTF16_IsHighSurrogate(c)) - { + if (SkUTF16_IsHighSurrogate(c)) { SkASSERT(src < stop); c = *src++; SkASSERT(SkUTF16_IsLowSurrogate(c)); @@ -351,16 +323,14 @@ int SkUTF16_CountUnichars(const uint16_t src[], int numberOf16BitValues) return count; } -SkUnichar SkUTF16_NextUnichar(const uint16_t** srcPtr) -{ +SkUnichar SkUTF16_NextUnichar(const uint16_t** srcPtr) { SkASSERT(srcPtr && *srcPtr); const uint16_t* src = *srcPtr; SkUnichar c = *src++; SkASSERT(!SkUTF16_IsLowSurrogate(c)); - if (SkUTF16_IsHighSurrogate(c)) - { + if (SkUTF16_IsHighSurrogate(c)) { unsigned c2 = *src++; SkASSERT(SkUTF16_IsLowSurrogate(c2)); @@ -372,16 +342,14 @@ SkUnichar SkUTF16_NextUnichar(const uint16_t** srcPtr) return c; } -SkUnichar SkUTF16_PrevUnichar(const uint16_t** srcPtr) -{ +SkUnichar SkUTF16_PrevUnichar(const uint16_t** srcPtr) { SkASSERT(srcPtr && *srcPtr); const uint16_t* src = *srcPtr; SkUnichar c = *--src; SkASSERT(!SkUTF16_IsHighSurrogate(c)); - if (SkUTF16_IsLowSurrogate(c)) - { + if (SkUTF16_IsLowSurrogate(c)) { unsigned c2 = *--src; SkASSERT(SkUTF16_IsHighSurrogate(c2)); c = (c2 << 10) + c + (0x10000 - (0xD800 << 10) - 0xDC00); @@ -390,16 +358,13 @@ SkUnichar SkUTF16_PrevUnichar(const uint16_t** srcPtr) return c; } -size_t SkUTF16_FromUnichar(SkUnichar uni, uint16_t dst[]) -{ +size_t SkUTF16_FromUnichar(SkUnichar uni, uint16_t dst[]) { SkASSERT((unsigned)uni <= 0x10FFFF); int extra = (uni > 0xFFFF); - if (dst) - { - if (extra) - { + if (dst) { + if (extra) { // dst[0] = SkToU16(0xD800 | ((uni - 0x10000) >> 10)); // dst[0] = SkToU16(0xD800 | ((uni >> 10) - 64)); dst[0] = SkToU16((0xD800 - 64) + (uni >> 10)); @@ -407,9 +372,7 @@ size_t SkUTF16_FromUnichar(SkUnichar uni, uint16_t dst[]) SkASSERT(SkUTF16_IsHighSurrogate(dst[0])); SkASSERT(SkUTF16_IsLowSurrogate(dst[1])); - } - else - { + } else { dst[0] = SkToU16(uni); SkASSERT(!SkUTF16_IsHighSurrogate(dst[0])); SkASSERT(!SkUTF16_IsLowSurrogate(dst[0])); @@ -418,46 +381,44 @@ size_t SkUTF16_FromUnichar(SkUnichar uni, uint16_t dst[]) return 1 + extra; } -size_t SkUTF16_ToUTF8(const uint16_t utf16[], int numberOf16BitValues, char utf8[]) -{ +size_t SkUTF16_ToUTF8(const uint16_t utf16[], int numberOf16BitValues, + char utf8[]) { SkASSERT(numberOf16BitValues >= 0); - if (numberOf16BitValues <= 0) + if (numberOf16BitValues <= 0) { return 0; + } SkASSERT(utf16 != NULL); const uint16_t* stop = utf16 + numberOf16BitValues; size_t size = 0; - if (utf8 == NULL) // just count - { - while (utf16 < stop) + if (utf8 == NULL) { // just count + while (utf16 < stop) { size += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), NULL); - } - else - { + } + } else { char* start = utf8; - while (utf16 < stop) + while (utf16 < stop) { utf8 += SkUTF8_FromUnichar(SkUTF16_NextUnichar(&utf16), utf8); + } size = utf8 - start; } return size; } -//////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// #include <stdlib.h> #if 0 -static int round_to_K(size_t bytes) -{ +static int round_to_K(size_t bytes) { return (bytes + 512) >> 10; } #endif SkAutoMemoryUsageProbe::SkAutoMemoryUsageProbe(const char label[]) - : fLabel(label) -{ + : fLabel(label) { #if 0 struct mallinfo mi = mallinfo(); @@ -465,14 +426,14 @@ SkAutoMemoryUsageProbe::SkAutoMemoryUsageProbe(const char label[]) #endif } -SkAutoMemoryUsageProbe::~SkAutoMemoryUsageProbe() -{ +SkAutoMemoryUsageProbe::~SkAutoMemoryUsageProbe() { #if 0 struct mallinfo mi = mallinfo(); printf("SkAutoMemoryUsageProbe "); - if (fLabel) + if (fLabel) { printf("<%s> ", fLabel); + } printf("delta %dK, current total allocated %dK\n", round_to_K(mi.uordblks - fBytesAllocated), round_to_K(mi.uordblks)); |