forked from firka/flutter
Pass std::string_view by value not by ref (flutter/engine#33699)
String views are small, cheap objects that fit in a couple registers, so passing by value avoids pointer indirection and thus a memory load. Fun related reading for future archaeologists: https://quuxplusone.github.io/blog/2021/11/09/pass-string-view-by-value/ And a Windows-specific footnote: https://quuxplusone.github.io/blog/2021/11/19/string-view-by-value-ps/ No test change since there is no semantic change.
This commit is contained in:
@@ -304,7 +304,7 @@ static std::string ToString(CompilerBackend::Type type) {
|
||||
}
|
||||
|
||||
std::shared_ptr<fml::Mapping> Reflector::InflateTemplate(
|
||||
const std::string_view& tmpl) const {
|
||||
std::string_view tmpl) const {
|
||||
inja::Environment env;
|
||||
env.set_trim_blocks(true);
|
||||
env.set_lstrip_blocks(true);
|
||||
|
||||
@@ -91,8 +91,7 @@ class Reflector {
|
||||
|
||||
std::shared_ptr<fml::Mapping> GenerateReflectionCC() const;
|
||||
|
||||
std::shared_ptr<fml::Mapping> InflateTemplate(
|
||||
const std::string_view& tmpl) const;
|
||||
std::shared_ptr<fml::Mapping> InflateTemplate(std::string_view tmpl) const;
|
||||
|
||||
std::optional<nlohmann::json::object_t> ReflectResource(
|
||||
const spirv_cross::Resource& resource) const;
|
||||
|
||||
@@ -94,7 +94,7 @@ bool ShaderLibraryGLES::IsValid() const {
|
||||
|
||||
// |ShaderLibrary|
|
||||
std::shared_ptr<const ShaderFunction> ShaderLibraryGLES::GetFunction(
|
||||
const std::string_view& name,
|
||||
std::string_view name,
|
||||
ShaderStage stage) {
|
||||
const auto key = ShaderKey{name, stage};
|
||||
if (auto found = functions_.find(key); found != functions_.end()) {
|
||||
|
||||
@@ -30,9 +30,8 @@ class ShaderLibraryGLES final : public ShaderLibrary {
|
||||
std::vector<std::shared_ptr<fml::Mapping>> shader_libraries);
|
||||
|
||||
// |ShaderLibrary|
|
||||
std::shared_ptr<const ShaderFunction> GetFunction(
|
||||
const std::string_view& name,
|
||||
ShaderStage stage) override;
|
||||
std::shared_ptr<const ShaderFunction> GetFunction(std::string_view name,
|
||||
ShaderStage stage) override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ShaderLibraryGLES);
|
||||
};
|
||||
|
||||
@@ -79,7 +79,7 @@ bool TextureGLES::IsValid() const {
|
||||
}
|
||||
|
||||
// |Texture|
|
||||
void TextureGLES::SetLabel(const std::string_view& label) {
|
||||
void TextureGLES::SetLabel(std::string_view label) {
|
||||
reactor_->SetDebugLabel(handle_, std::string{label.data(), label.size()});
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class TextureGLES final : public Texture,
|
||||
bool is_wrapped);
|
||||
|
||||
// |Texture|
|
||||
void SetLabel(const std::string_view& label) override;
|
||||
void SetLabel(std::string_view label) override;
|
||||
|
||||
// |Texture|
|
||||
bool OnSetContents(const uint8_t* contents,
|
||||
|
||||
@@ -39,9 +39,8 @@ class ShaderLibraryMTL final : public ShaderLibrary {
|
||||
ShaderLibraryMTL(NSArray<id<MTLLibrary>>* libraries);
|
||||
|
||||
// |ShaderLibrary|
|
||||
std::shared_ptr<const ShaderFunction> GetFunction(
|
||||
const std::string_view& name,
|
||||
ShaderStage stage) override;
|
||||
std::shared_ptr<const ShaderFunction> GetFunction(std::string_view name,
|
||||
ShaderStage stage) override;
|
||||
|
||||
FML_DISALLOW_COPY_AND_ASSIGN(ShaderLibraryMTL);
|
||||
};
|
||||
|
||||
@@ -24,7 +24,7 @@ bool ShaderLibraryMTL::IsValid() const {
|
||||
}
|
||||
|
||||
std::shared_ptr<const ShaderFunction> ShaderLibraryMTL::GetFunction(
|
||||
const std::string_view& name,
|
||||
std::string_view name,
|
||||
ShaderStage stage) {
|
||||
if (!IsValid()) {
|
||||
return nullptr;
|
||||
|
||||
@@ -27,7 +27,7 @@ class TextureMTL final : public Texture,
|
||||
bool is_valid_ = false;
|
||||
|
||||
// |Texture|
|
||||
void SetLabel(const std::string_view& label) override;
|
||||
void SetLabel(std::string_view label) override;
|
||||
|
||||
// |Texture|
|
||||
bool OnSetContents(const uint8_t* contents,
|
||||
|
||||
@@ -26,7 +26,7 @@ TextureMTL::TextureMTL(TextureDescriptor p_desc, id<MTLTexture> texture)
|
||||
|
||||
TextureMTL::~TextureMTL() = default;
|
||||
|
||||
void TextureMTL::SetLabel(const std::string_view& label) {
|
||||
void TextureMTL::SetLabel(std::string_view label) {
|
||||
[texture_ setLabel:@(label.data())];
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ struct ShaderKey {
|
||||
std::string name;
|
||||
ShaderStage stage = ShaderStage::kUnknown;
|
||||
|
||||
ShaderKey(const std::string_view& p_name, ShaderStage p_stage)
|
||||
ShaderKey(std::string_view p_name, ShaderStage p_stage)
|
||||
: name({p_name.data(), p_name.size()}), stage(p_stage) {}
|
||||
|
||||
struct Hash {
|
||||
|
||||
@@ -22,7 +22,7 @@ class ShaderLibrary {
|
||||
virtual bool IsValid() const = 0;
|
||||
|
||||
virtual std::shared_ptr<const ShaderFunction> GetFunction(
|
||||
const std::string_view& name,
|
||||
std::string_view name,
|
||||
ShaderStage stage) = 0;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -18,7 +18,7 @@ class Texture {
|
||||
public:
|
||||
virtual ~Texture();
|
||||
|
||||
virtual void SetLabel(const std::string_view& label) = 0;
|
||||
virtual void SetLabel(std::string_view label) = 0;
|
||||
|
||||
[[nodiscard]] bool SetContents(const uint8_t* contents,
|
||||
size_t length,
|
||||
|
||||
Reference in New Issue
Block a user