Files
react-native/ReactCommon/fabric/core/layout/LayoutConstraints.h
T
Valentin Shergin 948398519d 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
2019-03-14 18:35:00 -07:00

55 lines
1.3 KiB
C++

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <folly/Hash.h>
#include <react/core/LayoutPrimitives.h>
#include <react/graphics/Geometry.h>
namespace facebook {
namespace react {
/*
* Unified layout constraints for measuring.
*/
struct LayoutConstraints {
Size minimumSize{0, 0};
Size maximumSize{kFloatUndefined, kFloatUndefined};
LayoutDirection layoutDirection{LayoutDirection::Undefined};
/*
* Clamps the provided `Size` between the `minimumSize` and `maximumSize`
* bounds of this `LayoutConstraints`.
*/
Size clamp(const Size &size) const;
};
inline bool operator==(
const LayoutConstraints &lhs,
const LayoutConstraints &rhs) {
return std::tie(lhs.minimumSize, lhs.maximumSize, lhs.layoutDirection) ==
std::tie(rhs.minimumSize, rhs.maximumSize, rhs.layoutDirection);
}
} // namespace react
} // namespace facebook
namespace std {
template <>
struct hash<facebook::react::LayoutConstraints> {
size_t operator()(
const facebook::react::LayoutConstraints &constraints) const {
return folly::hash::hash_combine(
0,
constraints.minimumSize,
constraints.maximumSize,
constraints.layoutDirection);
}
};
} // namespace std