lookup received factories directly

Instead of mapping int -> name -> factory, map int -> factory.

The counterpart of https://skia-review.googlesource.com/c/skia/+/168264,
this time for the receiver.

Change-Id: I8c7756b1e5519611e72cba7d4aa88976169375af
Reviewed-on: https://skia-review.googlesource.com/c/171044
Reviewed-by: Khushal Sagar <khushalsagar@chromium.org>
Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Klein 2018-11-14 14:35:48 -05:00 committed by Skia Commit-Bot
parent 1315333b6b
commit 72098a44ff
2 changed files with 9 additions and 10 deletions

View File

@ -385,13 +385,13 @@ SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) {
}
factory = fFactoryArray[index];
} else {
SkString name;
if (this->peekByte()) {
// If the first byte is non-zero, the flattenable is specified by a string.
SkString name;
this->readString(&name);
// Add the string to the dictionary.
fFlattenableDict.set(fFlattenableDict.count() + 1, name);
factory = SkFlattenable::NameToFactory(name.c_str());
fFlattenableDict.set(fFlattenableDict.count() + 1, factory);
} else {
// Read the index. We are guaranteed that the first byte
// is zeroed, so we must shift down a byte.
@ -399,15 +399,14 @@ SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) {
if (index == 0) {
return nullptr; // writer failed to give us the flattenable
}
SkString* namePtr = fFlattenableDict.find(index);
if (!this->validate(namePtr != nullptr)) {
return nullptr;
if (SkFlattenable::Factory* found = fFlattenableDict.find(index)) {
factory = *found;
}
name = *namePtr;
}
if (!(factory = SkFlattenable::NameToFactory(name.c_str()))) {
return nullptr; // writer failed to give us the flattenable
if (!this->validate(factory != nullptr)) {
return nullptr;
}
}

View File

@ -208,7 +208,7 @@ private:
SkReader32 fReader;
// Only used if we do not have an fFactoryArray.
SkTHashMap<uint32_t, SkString> fFlattenableDict;
SkTHashMap<uint32_t, SkFlattenable::Factory> fFlattenableDict;
int fVersion;