mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Changing some T& to const T&, removing unnecessary shared_ptr. Reviewed By: shergin Differential Revision: D13845619 fbshipit-source-id: 2678f67f24445e3db105619a07534f5200e313fe
54 lines
1.4 KiB
C++
54 lines
1.4 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/container/EvictingCacheMap.h>
|
|
|
|
#include <react/attributedstring/AttributedString.h>
|
|
#include <react/attributedstring/ParagraphAttributes.h>
|
|
#include <react/core/LayoutConstraints.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
using ParagraphMeasurementCacheKey =
|
|
std::tuple<AttributedString, ParagraphAttributes, LayoutConstraints>;
|
|
using ParagraphMeasurementCacheValue = Size;
|
|
|
|
class ParagraphMeasurementCache {
|
|
public:
|
|
ParagraphMeasurementCache() : cache_{256} {}
|
|
|
|
bool exists(const ParagraphMeasurementCacheKey &key) const {
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
return cache_.exists(key);
|
|
}
|
|
|
|
ParagraphMeasurementCacheValue get(
|
|
const ParagraphMeasurementCacheKey &key) const {
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
return cache_.get(key);
|
|
}
|
|
|
|
void set(
|
|
const ParagraphMeasurementCacheKey &key,
|
|
const ParagraphMeasurementCacheValue &value) const {
|
|
std::lock_guard<std::mutex> lock(mutex_);
|
|
cache_.set(key, value);
|
|
}
|
|
|
|
private:
|
|
mutable folly::EvictingCacheMap<
|
|
ParagraphMeasurementCacheKey,
|
|
ParagraphMeasurementCacheValue>
|
|
cache_;
|
|
mutable std::mutex mutex_;
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|