Fabric: Fixing usage of Folly's hash_combine

Summary:
Accidentally I noticed that the signature of Folly's hash_combine is different from boost's one.
The Folly's one is:
`size_t hash_combine(const T& t, const Ts&... ts)`, so the first argument is immutable and the method returns the result normally.
It means that all hashes that we compute in Fabric using `hash_combine` were `0`.
So I fixed it.

I have no idea why this difference exists, but some modern papers suggest that folly's variant has good chances to be standardized.
E.g.: http://open-std.org/JTC1/SC22/WG21/docs/papers/2017/p0814r0.pdf

Technically, it should improve performance, but I doubt that it can be more than 1-2 ms per screen TTI.

Reviewed By: JoshuaGross

Differential Revision: D14430380

fbshipit-source-id: 97da999ee5780b940bb789bc3eb5bf9f89c194ca
This commit is contained in:
Valentin Shergin
2019-03-14 18:31:06 -07:00
committed by Facebook Github Bot
parent 4aa731ae76
commit 948398519d
6 changed files with 18 additions and 38 deletions

View File

@@ -95,14 +95,12 @@ template <>
struct hash<facebook::react::AttributedString::Fragment> {
size_t operator()(
const facebook::react::AttributedString::Fragment &fragment) const {
auto seed = size_t{0};
folly::hash::hash_combine(
seed,
return folly::hash::hash_combine(
0,
fragment.string,
fragment.textAttributes,
fragment.shadowView,
fragment.parentShadowView);
return seed;
}
};
@@ -113,7 +111,7 @@ struct hash<facebook::react::AttributedString> {
auto seed = size_t{0};
for (const auto &fragment : attributedString.getFragments()) {
folly::hash::hash_combine(seed, fragment);
seed = folly::hash::hash_combine(seed, fragment);
}
return seed;

View File

@@ -73,15 +73,13 @@ template <>
struct hash<facebook::react::ParagraphAttributes> {
size_t operator()(
const facebook::react::ParagraphAttributes &attributes) const {
auto seed = size_t{0};
folly::hash::hash_combine(
seed,
return folly::hash::hash_combine(
0,
attributes.maximumNumberOfLines,
attributes.ellipsizeMode,
attributes.adjustsFontSizeToFit,
attributes.minimumFontSize,
attributes.maximumFontSize);
return seed;
}
};
} // namespace std

View File

@@ -98,9 +98,8 @@ template <>
struct hash<facebook::react::TextAttributes> {
size_t operator()(
const facebook::react::TextAttributes &textAttributes) const {
auto seed = size_t{0};
folly::hash::hash_combine(
seed,
return folly::hash::hash_combine(
0,
textAttributes.foregroundColor,
textAttributes.backgroundColor,
textAttributes.opacity,
@@ -124,7 +123,6 @@ struct hash<facebook::react::TextAttributes> {
textAttributes.textShadowColor,
textAttributes.isHighlighted,
textAttributes.layoutDirection);
return seed;
}
};
} // namespace std

View File

@@ -44,13 +44,11 @@ template <>
struct hash<facebook::react::LayoutConstraints> {
size_t operator()(
const facebook::react::LayoutConstraints &constraints) const {
auto seed = size_t{0};
folly::hash::hash_combine(
seed,
return folly::hash::hash_combine(
0,
constraints.minimumSize,
constraints.maximumSize,
constraints.layoutDirection);
return seed;
}
};
} // namespace std

View File

@@ -186,51 +186,41 @@ namespace std {
template <>
struct hash<facebook::react::Point> {
size_t operator()(const facebook::react::Point &point) const {
auto seed = size_t{0};
folly::hash::hash_combine(seed, point.x, point.y);
return seed;
return folly::hash::hash_combine(0, point.x, point.y);
}
};
template <>
struct hash<facebook::react::Size> {
size_t operator()(const facebook::react::Size &size) const {
auto seed = size_t{0};
folly::hash::hash_combine(seed, size.width, size.height);
return seed;
return folly::hash::hash_combine(0, size.width, size.height);
}
};
template <>
struct hash<facebook::react::Rect> {
size_t operator()(const facebook::react::Rect &rect) const {
auto seed = size_t{0};
folly::hash::hash_combine(seed, rect.origin, rect.size);
return seed;
return folly::hash::hash_combine(0, rect.origin, rect.size);
}
};
template <typename T>
struct hash<facebook::react::RectangleEdges<T>> {
size_t operator()(const facebook::react::RectangleEdges<T> &edges) const {
auto seed = size_t{0};
folly::hash::hash_combine(
seed, edges.left, edges.right, edges.top, edges.bottom);
return seed;
return folly::hash::hash_combine(
0, edges.left, edges.right, edges.top, edges.bottom);
}
};
template <typename T>
struct hash<facebook::react::RectangleCorners<T>> {
size_t operator()(const facebook::react::RectangleCorners<T> &corners) const {
auto seed = size_t{0};
folly::hash::hash_combine(
seed,
return folly::hash::hash_combine(
0,
corners.topLeft,
corners.bottomLeft,
corners.topRight,
corners.bottomRight);
return seed;
}
};

View File

@@ -71,15 +71,13 @@ namespace std {
template <>
struct hash<facebook::react::ShadowView> {
size_t operator()(const facebook::react::ShadowView &shadowView) const {
auto seed = size_t{0};
folly::hash::hash_combine(
seed,
return folly::hash::hash_combine(
0,
shadowView.componentHandle,
shadowView.tag,
shadowView.props,
shadowView.eventEmitter,
shadowView.localData);
return seed;
}
};