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:
parent
1315333b6b
commit
72098a44ff
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user