inline strcmp for faster json parsing

pays off around 5% for skottie files (total load time)

Could be better if we knew the length of either/both arguments... Seems like we can likely know that a lot of the time.

Bug: skia:
Change-Id: I221e41be2f887ec98476479e012f64bb0ea09b54
Reviewed-on: https://skia-review.googlesource.com/147045
Reviewed-by: Mike Reed <reed@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2018-08-13 17:18:47 -04:00 committed by Skia Commit-Bot
parent aa166bd744
commit 0edad3e46d

View File

@ -186,6 +186,19 @@ ObjectValue::ObjectValue(const Member* src, size_t size, SkArenaAlloc& alloc) {
// Boring public Value glue.
static int inline_strcmp(const char a[], const char b[]) {
for (;;) {
char c = *a++;
if (c == 0) {
break;
}
if (c != *b++) {
return 1;
}
}
return *b != 0;
}
const Value& ObjectValue::operator[](const char* key) const {
// Reverse search for duplicates resolution (policy: return last).
const auto* begin = this->begin();
@ -193,7 +206,7 @@ const Value& ObjectValue::operator[](const char* key) const {
while (member > begin) {
--member;
if (0 == strcmp(key, member->fKey.as<StringValue>().begin())) {
if (0 == inline_strcmp(key, member->fKey.as<StringValue>().begin())) {
return member->fValue;
}
}