Update hash functions to use folly:#️⃣:hash_combine
Summary: Following hashing best practices. Reviewed By: shergin Differential Revision: D13827893 fbshipit-source-id: 3786f1e42b176a973890989be7b33efce4825ac6
This commit is contained in:
parent
6418e30e90
commit
88bc80c518
|
@ -91,10 +91,12 @@ 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, fragment.string);
|
||||
folly::hash::hash_combine(seed, fragment.textAttributes);
|
||||
folly::hash::hash_combine(seed, fragment.shadowView);
|
||||
folly::hash::hash_combine(seed, fragment.parentShadowView);
|
||||
folly::hash::hash_combine(
|
||||
seed,
|
||||
fragment.string,
|
||||
fragment.textAttributes,
|
||||
fragment.shadowView,
|
||||
fragment.parentShadowView);
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -73,15 +73,15 @@ template <>
|
|||
struct hash<facebook::react::ParagraphAttributes> {
|
||||
size_t operator()(
|
||||
const facebook::react::ParagraphAttributes &attributes) const {
|
||||
size_t seed = 0;
|
||||
folly::hash::hash_combine(seed, attributes.maximumNumberOfLines);
|
||||
folly::hash::hash_combine(seed, attributes.ellipsizeMode);
|
||||
folly::hash::hash_combine(seed, attributes.adjustsFontSizeToFit);
|
||||
auto seed = size_t{0};
|
||||
folly::hash::hash_combine(
|
||||
seed, std::hash<float>{}(attributes.minimumFontSize));
|
||||
folly::hash::hash_combine(
|
||||
seed, std::hash<float>{}(attributes.maximumFontSize));
|
||||
return hash<int>()(seed);
|
||||
seed,
|
||||
attributes.maximumNumberOfLines,
|
||||
attributes.ellipsizeMode,
|
||||
attributes.adjustsFontSizeToFit,
|
||||
attributes.minimumFontSize,
|
||||
attributes.maximumFontSize);
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <functional>
|
||||
#include <limits>
|
||||
|
||||
#include <folly/Hash.h>
|
||||
#include <folly/Optional.h>
|
||||
#include <react/attributedstring/primitives.h>
|
||||
#include <react/core/LayoutPrimitives.h>
|
||||
|
@ -92,55 +93,38 @@ class TextAttributes : public DebugStringConvertible {
|
|||
} // namespace facebook
|
||||
|
||||
namespace std {
|
||||
|
||||
template <>
|
||||
struct hash<facebook::react::TextAttributes> {
|
||||
size_t operator()(
|
||||
const facebook::react::TextAttributes &textAttributes) const {
|
||||
return std::hash<decltype(textAttributes.foregroundColor)>{}(
|
||||
textAttributes.foregroundColor) +
|
||||
std::hash<decltype(textAttributes.backgroundColor)>{}(
|
||||
textAttributes.backgroundColor) +
|
||||
std::hash<decltype(textAttributes.opacity)>{}(textAttributes.opacity) +
|
||||
std::hash<decltype(textAttributes.fontFamily)>{}(
|
||||
textAttributes.fontFamily) +
|
||||
std::hash<decltype(textAttributes.fontSize)>{}(
|
||||
textAttributes.fontSize) +
|
||||
std::hash<decltype(textAttributes.fontSizeMultiplier)>{}(
|
||||
textAttributes.fontSizeMultiplier) +
|
||||
std::hash<decltype(textAttributes.fontWeight)>{}(
|
||||
textAttributes.fontWeight) +
|
||||
std::hash<decltype(textAttributes.fontStyle)>{}(
|
||||
textAttributes.fontStyle) +
|
||||
std::hash<decltype(textAttributes.fontVariant)>{}(
|
||||
textAttributes.fontVariant) +
|
||||
std::hash<decltype(textAttributes.allowFontScaling)>{}(
|
||||
textAttributes.allowFontScaling) +
|
||||
std::hash<decltype(textAttributes.letterSpacing)>{}(
|
||||
textAttributes.letterSpacing) +
|
||||
std::hash<decltype(textAttributes.lineHeight)>{}(
|
||||
textAttributes.lineHeight) +
|
||||
std::hash<decltype(textAttributes.alignment)>{}(
|
||||
textAttributes.alignment) +
|
||||
std::hash<decltype(textAttributes.baseWritingDirection)>{}(
|
||||
textAttributes.baseWritingDirection) +
|
||||
std::hash<decltype(textAttributes.textDecorationColor)>{}(
|
||||
textAttributes.textDecorationColor) +
|
||||
std::hash<decltype(textAttributes.textDecorationLineType)>{}(
|
||||
textAttributes.textDecorationLineType) +
|
||||
std::hash<decltype(textAttributes.textDecorationLineStyle)>{}(
|
||||
textAttributes.textDecorationLineStyle) +
|
||||
std::hash<decltype(textAttributes.textDecorationLinePattern)>{}(
|
||||
textAttributes.textDecorationLinePattern) +
|
||||
std::hash<decltype(textAttributes.textShadowOffset)>{}(
|
||||
textAttributes.textShadowOffset) +
|
||||
std::hash<decltype(textAttributes.textShadowRadius)>{}(
|
||||
textAttributes.textShadowRadius) +
|
||||
std::hash<decltype(textAttributes.textShadowColor)>{}(
|
||||
textAttributes.textShadowColor) +
|
||||
std::hash<decltype(textAttributes.isHighlighted)>{}(
|
||||
textAttributes.isHighlighted) +
|
||||
std::hash<decltype(textAttributes.layoutDirection)>{}(
|
||||
auto seed = size_t{0};
|
||||
folly::hash::hash_combine(
|
||||
seed,
|
||||
textAttributes.foregroundColor,
|
||||
textAttributes.backgroundColor,
|
||||
textAttributes.opacity,
|
||||
textAttributes.fontFamily,
|
||||
textAttributes.fontSize,
|
||||
textAttributes.fontSizeMultiplier,
|
||||
textAttributes.fontWeight,
|
||||
textAttributes.fontStyle,
|
||||
textAttributes.fontVariant,
|
||||
textAttributes.allowFontScaling,
|
||||
textAttributes.letterSpacing,
|
||||
textAttributes.lineHeight,
|
||||
textAttributes.alignment,
|
||||
textAttributes.baseWritingDirection,
|
||||
textAttributes.textDecorationColor,
|
||||
textAttributes.textDecorationLineType,
|
||||
textAttributes.textDecorationLineStyle,
|
||||
textAttributes.textDecorationLinePattern,
|
||||
textAttributes.textShadowOffset,
|
||||
textAttributes.textShadowRadius,
|
||||
textAttributes.textShadowColor,
|
||||
textAttributes.isHighlighted,
|
||||
textAttributes.layoutDirection);
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
|
|
@ -36,14 +36,15 @@ inline bool operator==(
|
|||
namespace std {
|
||||
template <>
|
||||
struct hash<facebook::react::LayoutConstraints> {
|
||||
size_t operator()(const facebook::react::LayoutConstraints &v) const {
|
||||
size_t seed = 0;
|
||||
size_t operator()(
|
||||
const facebook::react::LayoutConstraints &constraints) const {
|
||||
auto seed = size_t{0};
|
||||
folly::hash::hash_combine(
|
||||
seed, std::hash<facebook::react::Size>()(v.minimumSize));
|
||||
folly::hash::hash_combine(
|
||||
seed, std::hash<facebook::react::Size>()(v.maximumSize));
|
||||
folly::hash::hash_combine(seed, v.layoutDirection);
|
||||
return hash<int>()(seed);
|
||||
seed,
|
||||
constraints.minimumSize,
|
||||
constraints.maximumSize,
|
||||
constraints.layoutDirection);
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <functional>
|
||||
#include <tuple>
|
||||
|
||||
#include <folly/Hash.h>
|
||||
#include <react/graphics/Float.h>
|
||||
|
||||
namespace facebook {
|
||||
|
@ -185,44 +186,51 @@ namespace std {
|
|||
template <>
|
||||
struct hash<facebook::react::Point> {
|
||||
size_t operator()(const facebook::react::Point &point) const {
|
||||
return hash<decltype(point.x)>{}(point.x) +
|
||||
hash<decltype(point.y)>{}(point.y);
|
||||
auto seed = size_t{0};
|
||||
folly::hash::hash_combine(seed, point.x, point.y);
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<facebook::react::Size> {
|
||||
size_t operator()(const facebook::react::Size &size) const {
|
||||
return hash<decltype(size.width)>{}(size.width) +
|
||||
hash<decltype(size.height)>{}(size.height);
|
||||
auto seed = size_t{0};
|
||||
folly::hash::hash_combine(seed, size.width, size.height);
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct hash<facebook::react::Rect> {
|
||||
size_t operator()(const facebook::react::Rect &rect) const {
|
||||
return hash<decltype(rect.origin)>{}(rect.origin) +
|
||||
hash<decltype(rect.size)>{}(rect.size);
|
||||
auto seed = size_t{0};
|
||||
folly::hash::hash_combine(seed, rect.origin, rect.size);
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct hash<facebook::react::RectangleEdges<T>> {
|
||||
size_t operator()(const facebook::react::RectangleEdges<T> &edges) const {
|
||||
return hash<decltype(edges.left)>{}(edges.left) +
|
||||
hash<decltype(edges.right)>{}(edges.right) +
|
||||
hash<decltype(edges.top)>{}(edges.top) +
|
||||
hash<decltype(edges.bottom)>{}(edges.bottom);
|
||||
auto seed = size_t{0};
|
||||
folly::hash::hash_combine(
|
||||
seed, edges.left, edges.right, edges.top, edges.bottom);
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct hash<facebook::react::RectangleCorners<T>> {
|
||||
size_t operator()(const facebook::react::RectangleCorners<T> &corners) const {
|
||||
return hash<decltype(corners.topLeft)>{}(corners.topLeft) +
|
||||
hash<decltype(corners.bottomLeft)>{}(corners.bottomLeft) +
|
||||
hash<decltype(corners.topRight)>{}(corners.topRight) +
|
||||
hash<decltype(corners.bottomRight)>{}(corners.bottomRight);
|
||||
auto seed = size_t{0};
|
||||
folly::hash::hash_combine(
|
||||
seed,
|
||||
corners.topLeft,
|
||||
corners.bottomLeft,
|
||||
corners.topRight,
|
||||
corners.bottomRight);
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <folly/Hash.h>
|
||||
#include <react/core/LayoutMetrics.h>
|
||||
#include <react/core/LocalData.h>
|
||||
#include <react/core/Props.h>
|
||||
|
@ -65,13 +66,15 @@ namespace std {
|
|||
template <>
|
||||
struct hash<facebook::react::ShadowView> {
|
||||
size_t operator()(const facebook::react::ShadowView &shadowView) const {
|
||||
return std::hash<decltype(shadowView.componentHandle)>{}(
|
||||
shadowView.componentHandle) +
|
||||
std::hash<decltype(shadowView.tag)>{}(shadowView.tag) +
|
||||
std::hash<decltype(shadowView.props)>{}(shadowView.props) +
|
||||
std::hash<decltype(shadowView.eventEmitter)>{}(
|
||||
shadowView.eventEmitter) +
|
||||
std::hash<decltype(shadowView.localData)>{}(shadowView.localData);
|
||||
auto seed = size_t{0};
|
||||
folly::hash::hash_combine(
|
||||
seed,
|
||||
shadowView.componentHandle,
|
||||
shadowView.tag,
|
||||
shadowView.props,
|
||||
shadowView.eventEmitter,
|
||||
shadowView.localData);
|
||||
return seed;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue