utils: Add FastStrcmp.h
Move existing fast<str*cmp> templates for general use, pulled from
the implementation used in logd that dealt with speed through cache
locality and subroutine call mitigation. Rename to fastcmp.
Test: logd-benchmarks and based on manual profiling from the past
Bug: 31456426
Change-Id: Ic62f4a437fc3e06ffdeaae73a6f34e197957a6b0
diff --git a/logd/LogKlog.cpp b/logd/LogKlog.cpp
index 7073535..0b49fc1 100644
--- a/logd/LogKlog.cpp
+++ b/logd/LogKlog.cpp
@@ -321,7 +321,7 @@
}
--len;
} while (*s++ != c);
- } while (fast<memcmp>(s, needle, needleLen));
+ } while (fastcmp<memcmp>(s, needle, needleLen));
s--;
}
return s;
@@ -640,7 +640,7 @@
static const char infoBrace[] = "[INFO]";
static const size_t infoBraceLen = strlen(infoBrace);
- if ((taglen >= infoBraceLen) && !fast<strncmp>(p, infoBrace, infoBraceLen)) {
+ if ((taglen >= infoBraceLen) && !fastcmp<strncmp>(p, infoBrace, infoBraceLen)) {
// <PRI>[<TIME>] "[INFO]"<tag> ":" message
bt = p + infoBraceLen;
taglen -= infoBraceLen;
@@ -675,7 +675,7 @@
p = cp + 1;
} else if ((taglen > size) && (tolower(*bt) == tolower(*cp))) {
// clean up any tag stutter
- if (!fast<strncasecmp>(bt + 1, cp + 1, size - 1)) { // no match
+ if (!fastcmp<strncasecmp>(bt + 1, cp + 1, size - 1)) { // no match
// <PRI>[<TIME>] <tag> <tag> : message
// <PRI>[<TIME>] <tag> <tag>: message
// <PRI>[<TIME>] <tag> '<tag>.<num>' : message
@@ -697,8 +697,8 @@
static const char host[] = "_host";
static const size_t hostlen = strlen(host);
if ((size > hostlen) &&
- !fast<strncmp>(bt + size - hostlen, host, hostlen) &&
- !fast<strncmp>(bt + 1, cp + 1, size - hostlen - 1)) {
+ !fastcmp<strncmp>(bt + size - hostlen, host, hostlen) &&
+ !fastcmp<strncmp>(bt + 1, cp + 1, size - hostlen - 1)) {
const char *b = cp;
cp += size - hostlen;
taglen -= size - hostlen;
@@ -746,10 +746,10 @@
// register names like x18 but not driver names like en0
|| ((size == 3) && (isdigit(tag[1]) && isdigit(tag[2])))
// blacklist
- || ((size == cpuLen) && !fast<strncmp>(tag, cpu, cpuLen))
- || ((size == warningLen) && !fast<strncasecmp>(tag, warning, warningLen))
- || ((size == errorLen) && !fast<strncasecmp>(tag, error, errorLen))
- || ((size == infoLen) && !fast<strncasecmp>(tag, info, infoLen))) {
+ || ((size == cpuLen) && !fastcmp<strncmp>(tag, cpu, cpuLen))
+ || ((size == warningLen) && !fastcmp<strncasecmp>(tag, warning, warningLen))
+ || ((size == errorLen) && !fastcmp<strncasecmp>(tag, error, errorLen))
+ || ((size == infoLen) && !fastcmp<strncasecmp>(tag, info, infoLen))) {
p = start;
etag = tag = "";
}
@@ -761,7 +761,7 @@
const char *mp = strnrchr(tag, ']', taglen);
if (mp && (++mp < etag)) {
size_t s = etag - mp;
- if (((s + s) < taglen) && !fast<memcmp>(mp, mp - 1 - s, s)) {
+ if (((s + s) < taglen) && !fastcmp<memcmp>(mp, mp - 1 - s, s)) {
taglen = mp - tag;
}
}