Fabric: operator== and std::hash for AttributedStringBox

Summary:
That will allow building a custom caching table for boxed stings to cache text measurements for them in TextLayoutManager.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D18950428

fbshipit-source-id: 8ceef29543dc6ed540043e32d65f3295030ae90f
This commit is contained in:
Valentin Shergin
2019-12-12 12:53:12 -08:00
committed by Facebook Github Bot
parent 3b92d3187c
commit 909b0fe0e7
2 changed files with 39 additions and 0 deletions
@@ -40,5 +40,26 @@ std::shared_ptr<void> AttributedStringBox::getOpaquePointer() const {
return opaquePointer_;
}
bool operator==(
AttributedStringBox const &lhs,
AttributedStringBox const &rhs) {
if (lhs.getMode() != rhs.getMode()) {
return false;
}
switch (lhs.getMode()) {
case facebook::react::AttributedStringBox::Mode::Value:
return lhs.getValue() == rhs.getValue();
case facebook::react::AttributedStringBox::Mode::OpaquePointer:
return lhs.getOpaquePointer() == rhs.getOpaquePointer();
}
}
bool operator!=(
AttributedStringBox const &lhs,
AttributedStringBox const &rhs) {
return !(lhs == rhs);
}
} // namespace react
} // namespace facebook