Optimize some commonly used utf8 functions by:
- using counted loops instead of searching for terminating null. In the important cases the caller already knows the length: change the API to pass it in. Keep the old API version as well to avoid extensive changes to non-critical debug and test code. - ensure the common cases are at the start of if/then/else chains. Usually 99+% of characters are ASCII even in mixed strings. - for the "convert" functions, when both utf8 and utf16 lengths are passed, and are equal, it means the entire string is ASCII, and a specialized loop can be used. The compiler might then unroll or even vectorize this. The functions improved are (tested on Nexus 5 with a 44 character ASCII string): CountModifiedUtf8Chars : 20% faster ConvertUtf16ToModifiedUtf8: 80% faster ConvertModifiedUtf8ToUtf16: 200% faster Also for completeness CountUtf8Bytes has been cleaned up a little, but the speed is unchanged. Unlike CountModifiedUtf8Chars, it was already passed the length, rather than searching for null. Change-Id: I1c9b7dea3eda869fc9f5f6b4dd6be8cdd5bc3ac0
Loading
Please sign in to comment