Replaces Resource's shared_ptr with unique_ptr (flutter/engine#56778)

A non-inconsequential amount of time is spent in ~shared_ptr for no reason in ~Resource

<img width="1057" alt="Screenshot 2024-11-23 at 3 22 11 PM" src="https://github.com/user-attachments/assets/fba73908-2e43-4908-8008-ddd78fd77831">

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
gaaclarke 2024-11-24 12:01:34 -08:00 committed by GitHub
parent 8fb4a66d39
commit c1b6fd8c69

View File

@ -29,7 +29,8 @@ namespace impeller {
#endif // IMPELLER_DEBUG #endif // IMPELLER_DEBUG
template <class T> template <class T>
struct Resource { class Resource {
public:
using ResourceType = T; using ResourceType = T;
ResourceType resource; ResourceType resource;
@ -40,7 +41,7 @@ struct Resource {
Resource(const ShaderMetadata& metadata, ResourceType p_resource) Resource(const ShaderMetadata& metadata, ResourceType p_resource)
: resource(p_resource), : resource(p_resource),
dynamic_metadata_(std::make_shared<ShaderMetadata>(metadata)) {} dynamic_metadata_(std::make_unique<ShaderMetadata>(metadata)) {}
const ShaderMetadata* GetMetadata() const { const ShaderMetadata* GetMetadata() const {
return dynamic_metadata_ ? dynamic_metadata_.get() : metadata_; return dynamic_metadata_ ? dynamic_metadata_.get() : metadata_;
@ -51,7 +52,7 @@ struct Resource {
const ShaderMetadata* metadata_ = nullptr; const ShaderMetadata* metadata_ = nullptr;
// Dynamically generated shader metadata. // Dynamically generated shader metadata.
std::shared_ptr<const ShaderMetadata> dynamic_metadata_ = nullptr; std::unique_ptr<const ShaderMetadata> dynamic_metadata_ = nullptr;
}; };
using BufferResource = Resource<BufferView>; using BufferResource = Resource<BufferView>;