mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-27 19:25:11 +08:00
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
86 lines
2.2 KiB
C++
86 lines
2.2 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 <limits>
|
|
|
|
#include <folly/Hash.h>
|
|
#include <react/attributedstring/primitives.h>
|
|
#include <react/debug/DebugStringConvertible.h>
|
|
#include <react/graphics/Geometry.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
class ParagraphAttributes;
|
|
|
|
using SharedParagraphAttributes = std::shared_ptr<const ParagraphAttributes>;
|
|
|
|
/*
|
|
* Represents all visual attributes of a paragraph of text.
|
|
* Two data structures, ParagraphAttributes and AttributedText, should be
|
|
* enough to define visual representation of a piece of text on the screen.
|
|
*/
|
|
class ParagraphAttributes : public DebugStringConvertible {
|
|
public:
|
|
#pragma mark - Fields
|
|
|
|
/*
|
|
* Maximum number of lines which paragraph can take.
|
|
* Zero value represents "no limit".
|
|
*/
|
|
int maximumNumberOfLines{};
|
|
|
|
/*
|
|
* In case if a text cannot fit given boundaries, defines a place where
|
|
* an ellipsize should be placed.
|
|
*/
|
|
EllipsizeMode ellipsizeMode{};
|
|
|
|
/*
|
|
* Enables font size adjustment to fit constrained boundaries.
|
|
*/
|
|
bool adjustsFontSizeToFit{};
|
|
|
|
/*
|
|
* In case of font size adjustment enabled, defines minimum and maximum
|
|
* font sizes.
|
|
*/
|
|
Float minimumFontSize{std::numeric_limits<Float>::quiet_NaN()};
|
|
Float maximumFontSize{std::numeric_limits<Float>::quiet_NaN()};
|
|
|
|
bool operator==(const ParagraphAttributes &) const;
|
|
bool operator!=(const ParagraphAttributes &) const;
|
|
|
|
#pragma mark - DebugStringConvertible
|
|
|
|
#if RN_DEBUG_STRING_CONVERTIBLE
|
|
SharedDebugStringConvertibleList getDebugProps() const override;
|
|
#endif
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|
|
|
|
namespace std {
|
|
|
|
template <>
|
|
struct hash<facebook::react::ParagraphAttributes> {
|
|
size_t operator()(
|
|
const facebook::react::ParagraphAttributes &attributes) const {
|
|
return folly::hash::hash_combine(
|
|
0,
|
|
attributes.maximumNumberOfLines,
|
|
attributes.ellipsizeMode,
|
|
attributes.adjustsFontSizeToFit,
|
|
attributes.minimumFontSize,
|
|
attributes.maximumFontSize);
|
|
}
|
|
};
|
|
} // namespace std
|