diff --git a/base/include/observer.h b/base/include/observer.h index 35811afbd289eccf3ccb8d5f54752d6694bcacf1..203fb6164c0f859afd1f42d029793d9001421f72 100644 --- a/base/include/observer.h +++ b/base/include/observer.h @@ -123,9 +123,5 @@ public: */ virtual void Update(const Observable* o, const ObserverArg* arg) = 0; }; - - } - -#endif - +#endif \ No newline at end of file diff --git a/base/include/pubdef.h b/base/include/pubdef.h index ef3ce615b50be8668599d404fc1f32ec45ee0885..7df8547cec0ab06054e5d249939f4b3d9c091028 100644 --- a/base/include/pubdef.h +++ b/base/include/pubdef.h @@ -43,9 +43,9 @@ namespace OHOS { #define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a[0]))) // Used to free the space pointed by pointer p -#define FREE_AND_NIL(p) do { if (p) { delete (p); (p) = nullptr; } } while(0) +#define FREE_AND_NIL(p) do {if (p) { delete (p); (p) = nullptr;}} while(0) // Used to free the array space pointed by pointer p -#define FREE_AND_NIL_ARRAY(p) do { if (p) { delete[] (p); (p) = nullptr; } } while(0) +#define FREE_AND_NIL_ARRAY(p) do {if (p) {delete[] (p); (p) = nullptr;}} while(0) // Used to return the maximum of two numbers #define MAX(x, y) (((x) > (y)) ? (x) : (y)) diff --git a/base/include/safe_queue.h b/base/include/safe_queue.h index 08929f1c8a6e2a40b69f52bafe4ba5289d90bf39..6cbfab47626be3016463b22744245a502fb51c90 100644 --- a/base/include/safe_queue.h +++ b/base/include/safe_queue.h @@ -38,7 +38,6 @@ namespace OHOS { */ template class SafeQueueInner { - public: SafeQueueInner() {} diff --git a/base/include/sorted_vector.h b/base/include/sorted_vector.h index 8da487d3df99a3039178b804efead71ff6d9c380..612f7a61f8a2c7181cbd1409dcd2f840a4ed0d9b 100644 --- a/base/include/sorted_vector.h +++ b/base/include/sorted_vector.h @@ -210,7 +210,6 @@ public: return vec_[index]; } - /** * @brief Merges a vector into this vector. * diff --git a/base/src/ashmem.cpp b/base/src/ashmem.cpp index 48a3bf73118ec0be583730cbb78ccdbb3557dd22..04adab4143577f989a71365e587a54c94831851d 100644 --- a/base/src/ashmem.cpp +++ b/base/src/ashmem.cpp @@ -66,7 +66,6 @@ const char* AsCharPtr(const c_void* inPtr) static int AshmemOpenLocked() { int fd = TEMP_FAILURE_RETRY(open("/dev/ashmem", O_RDWR | O_CLOEXEC)); - if (fd < 0) { UTILS_LOGE("%{public}s: fd is invalid, fd = %{public}d", __func__, fd); return fd; diff --git a/base/src/parcel.cpp b/base/src/parcel.cpp index 4d8311d5e6212aa9556aebda33fefbeda6475a44..ef607c541b8232449fcd87928b33d3939b9d808a 100644 --- a/base/src/parcel.cpp +++ b/base/src/parcel.cpp @@ -106,6 +106,7 @@ size_t Parcel::CalcNewCapacity(size_t minNewCapacity) size_t newCapacity = 64; while (newCapacity < minNewCapacity) { + // resize capacity by 2 times newCapacity = newCapacity * 2; } diff --git a/base/src/rwlock.cpp b/base/src/rwlock.cpp index 74b21fe255c94f15eccc803ecb9e04716ff39412..86baaf4457b0fdf4de6c660c90c35a4ac3c780ae 100644 --- a/base/src/rwlock.cpp +++ b/base/src/rwlock.cpp @@ -63,7 +63,7 @@ void RWLock::LockWrite() // Only when no thread has acquired a read lock or a write lock (the lock counter status is FREE) // can the write lock be acquired and the counter set to WRITE; otherwise wait - for(int status = LOCK_STATUS_FREE; !lockCount_.compare_exchange_weak(status, LOCK_STATUS_WRITE); + for (int status = LOCK_STATUS_FREE; !lockCount_.compare_exchange_weak(status, LOCK_STATUS_WRITE); status = LOCK_STATUS_FREE) { } diff --git a/base/src/string_ex.cpp b/base/src/string_ex.cpp index 0082ff75420c97f1c88826a7a6052247e1a4bd9e..0aa076b9b812939f336a3c04adc353ef84a4c8ec 100644 --- a/base/src/string_ex.cpp +++ b/base/src/string_ex.cpp @@ -233,7 +233,7 @@ bool IsSameTextStr(const string& first, const string& second) } /* - * utf8 rule: + * utf8 rule * 0000 ~ 007F : 0xxxxxxx * 0080 ~ 07FF : 110xxxxx 10xxxxxx * 0800 ~ FFFF : 1110xxxx 10xxxxxx 10xxxxxx diff --git a/base/src/unicode_ex.cpp b/base/src/unicode_ex.cpp index bb737360820aa4c6d37ec0be907fd8137ba40124..c21e39ee861d1f39bb714c473703218298a4f4e7 100644 --- a/base/src/unicode_ex.cpp +++ b/base/src/unicode_ex.cpp @@ -54,26 +54,44 @@ constexpr char32_t UTF8_FIRST_BYTE_MARK[] = { }; } +#define UTF8_LENGTH_INVALID 0 +#define UTF8_LENGTH_1 1 +#define UTF8_LENGTH_2 2 +#define UTF8_LENGTH_3 3 +#define UTF8_LENGTH_4 4 +#define UTF8_LEN_MASK 3 +#define UTF8_FIRST_BYTE_INDEX 0 +#define UTF8_SECOND_BYTE_INDEX 1 +#define UTF8_THIRD_BYTE_INDEX 2 +#define UTF8_FORTH_BYTE_INDEX 3 +#define UTF8_SHIFT_WIDTH 6 +#define STR16_TO_STR8_SHIFT_WIDTH 10 +#define UTF16_SHIFT_WIDTH 10 +#define UTF32_BYTE_SIZE_1 1 +#define UTF32_BYTE_SIZE_2 2 +#define UTF32_BYTE_SIZE_3 3 +#define UTF32_BYTE_SIZE_4 4 + // inner func and dstP is not nullptr void Utf32CodePointToUtf8(uint8_t* dstP, char32_t srcChar, size_t bytes) { dstP += bytes; - if (bytes >= 4) { + if (bytes >= UTF32_BYTE_SIZE_4) { *--dstP = static_cast((srcChar | UTF8_BYTE_MARK) & UTF8_BYTE_MASK); srcChar >>= UTF8_OFFSET; } - if (bytes >= 3) { + if (bytes >= UTF32_BYTE_SIZE_3) { *--dstP = static_cast((srcChar | UTF8_BYTE_MARK) & UTF8_BYTE_MASK); srcChar >>= UTF8_OFFSET; } - if (bytes >= 2) { + if (bytes >= UTF32_BYTE_SIZE_2) { *--dstP = static_cast((srcChar | UTF8_BYTE_MARK) & UTF8_BYTE_MASK); srcChar >>= UTF8_OFFSET; } - if (bytes >= 1) { + if (bytes >= UTF32_BYTE_SIZE_1) { *--dstP = static_cast(srcChar | UTF8_FIRST_BYTE_MARK[bytes]); } } @@ -81,22 +99,22 @@ void Utf32CodePointToUtf8(uint8_t* dstP, char32_t srcChar, size_t bytes) size_t Utf32CodePointUtf8Length(char32_t srcChar) { if (srcChar < ONE_BYTE_UTF8) { - return 1; + return UTF8_LENGTH_1; } else if (srcChar < TWO_BYTES_UTF8) { - return 2; + return UTF8_LENGTH_2; } else if (srcChar < THREE_BYTES_UTF8) { if ((srcChar < UNICODE_RESERVED_START) || (srcChar > UNICODE_RESERVED_END)) { - return 3; + return UTF8_LENGTH_3; } else { // Surrogates are invalid UTF-32 characters. - return 0; + return UTF8_LENGTH_INVALID; } } else if (srcChar <= UNICODE_MAX_NUM) { // Max code point for Unicode is 0x0010FFFF. - return 4; + return UTF8_LENGTH_4; } else { // Invalid UTF-32 character. - return 0; + return UTF8_LENGTH_INVALID; } } @@ -115,6 +133,7 @@ int Utf16ToUtf8Length(const char16_t* str16, size_t str16Len) && ((*(str16 + 1) & 0xFC00) == 0xDC00)) { // surrogate pairs are always 4 bytes. charLen = 4; + // str16 advance 2 bytes str16 += 2; } else { charLen = Utf32CodePointUtf8Length(static_cast(*str16++)); @@ -139,7 +158,7 @@ void StrncpyStr16ToStr8(const char16_t* utf16Str, size_t str16Len, char* utf8Str // surrogate pairs if (((*curUtf16 & 0xFC00) == 0xD800) && ((curUtf16 + 1) < endUtf16) && (((*(curUtf16 + 1) & 0xFC00)) == 0xDC00)) { - utf32 = (*curUtf16++ - 0xD800) << 10; + utf32 = (*curUtf16++ - 0xD800) << STR16_TO_STR8_SHIFT_WIDTH; utf32 |= *curUtf16++ - 0xDC00; utf32 += 0x10000; } else { @@ -206,12 +225,12 @@ bool String16ToString8(const u16string& str16, string& str8) */ static inline size_t Utf8CodePointLen(uint8_t ch) { - return ((0xe5000000 >> ((ch >> 3) & 0x1e)) & 3) + 1; + return ((0xe5000000 >> ((ch >> UTF8_LEN_MASK) & 0x1e)) & UTF8_LEN_MASK) + 1; } static inline void Utf8ShiftAndMask(uint32_t* codePoint, const uint8_t byte) { - *codePoint <<= 6; + *codePoint <<= UTF8_SHIFT_WIDTH; *codePoint |= 0x3F & byte; } @@ -220,22 +239,22 @@ uint32_t Utf8ToUtf32CodePoint(const char* src, size_t length) uint32_t unicode = 0; switch (length) { - case 1: - return src[0]; - case 2: - unicode = src[0] & 0x1f; - Utf8ShiftAndMask(&unicode, src[1]); + case UTF8_LENGTH_1: + return src[UTF8_FIRST_BYTE_INDEX]; + case UTF8_LENGTH_2: + unicode = src[UTF8_FIRST_BYTE_INDEX] & 0x1f; + Utf8ShiftAndMask(&unicode, src[UTF8_SECOND_BYTE_INDEX]); return unicode; - case 3: - unicode = src[0] & 0x0f; - Utf8ShiftAndMask(&unicode, src[1]); - Utf8ShiftAndMask(&unicode, src[2]); + case UTF8_LENGTH_3: + unicode = src[UTF8_FIRST_BYTE_INDEX] & 0x0f; + Utf8ShiftAndMask(&unicode, src[UTF8_SECOND_BYTE_INDEX]); + Utf8ShiftAndMask(&unicode, src[UTF8_THIRD_BYTE_INDEX]); return unicode; - case 4: - unicode = src[0] & 0x07; - Utf8ShiftAndMask(&unicode, src[1]); - Utf8ShiftAndMask(&unicode, src[2]); - Utf8ShiftAndMask(&unicode, src[3]); + case UTF8_LENGTH_4: + unicode = src[UTF8_FIRST_BYTE_INDEX] & 0x07; + Utf8ShiftAndMask(&unicode, src[UTF8_SECOND_BYTE_INDEX]); + Utf8ShiftAndMask(&unicode, src[UTF8_THIRD_BYTE_INDEX]); + Utf8ShiftAndMask(&unicode, src[UTF8_FORTH_BYTE_INDEX]); return unicode; default: return 0xffff; @@ -286,7 +305,7 @@ char16_t* Utf8ToUtf16(const char* utf8Str, size_t u8len, char16_t* u16str, size_ } else { // Multiple UTF16 characters with surrogates codepoint = codepoint - 0x10000; - *u16cur++ = static_cast((codepoint >> 10) + 0xD800); + *u16cur++ = static_cast((codepoint >> UTF16_SHIFT_WIDTH) + 0xD800); if (u16cur >= u16end) { // Ooops... not enough room for this surrogate pair. return u16cur - 1;