Skip to content

Commit 56e0c34

Browse files
authored
Pass std::string_view by value not by ref (flutter#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.
1 parent 1072576 commit 56e0c34

13 files changed

Lines changed: 15 additions & 18 deletions

impeller/compiler/reflector.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static std::string ToString(CompilerBackend::Type type) {
304304
}
305305

306306
std::shared_ptr<fml::Mapping> Reflector::InflateTemplate(
307-
const std::string_view& tmpl) const {
307+
std::string_view tmpl) const {
308308
inja::Environment env;
309309
env.set_trim_blocks(true);
310310
env.set_lstrip_blocks(true);

impeller/compiler/reflector.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ class Reflector {
9191

9292
std::shared_ptr<fml::Mapping> GenerateReflectionCC() const;
9393

94-
std::shared_ptr<fml::Mapping> InflateTemplate(
95-
const std::string_view& tmpl) const;
94+
std::shared_ptr<fml::Mapping> InflateTemplate(std::string_view tmpl) const;
9695

9796
std::optional<nlohmann::json::object_t> ReflectResource(
9897
const spirv_cross::Resource& resource) const;

impeller/renderer/backend/gles/shader_library_gles.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ bool ShaderLibraryGLES::IsValid() const {
9494

9595
// |ShaderLibrary|
9696
std::shared_ptr<const ShaderFunction> ShaderLibraryGLES::GetFunction(
97-
const std::string_view& name,
97+
std::string_view name,
9898
ShaderStage stage) {
9999
const auto key = ShaderKey{name, stage};
100100
if (auto found = functions_.find(key); found != functions_.end()) {

impeller/renderer/backend/gles/shader_library_gles.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ class ShaderLibraryGLES final : public ShaderLibrary {
3030
std::vector<std::shared_ptr<fml::Mapping>> shader_libraries);
3131

3232
// |ShaderLibrary|
33-
std::shared_ptr<const ShaderFunction> GetFunction(
34-
const std::string_view& name,
35-
ShaderStage stage) override;
33+
std::shared_ptr<const ShaderFunction> GetFunction(std::string_view name,
34+
ShaderStage stage) override;
3635

3736
FML_DISALLOW_COPY_AND_ASSIGN(ShaderLibraryGLES);
3837
};

impeller/renderer/backend/gles/texture_gles.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ bool TextureGLES::IsValid() const {
7979
}
8080

8181
// |Texture|
82-
void TextureGLES::SetLabel(const std::string_view& label) {
82+
void TextureGLES::SetLabel(std::string_view label) {
8383
reactor_->SetDebugLabel(handle_, std::string{label.data(), label.size()});
8484
}
8585

impeller/renderer/backend/gles/texture_gles.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class TextureGLES final : public Texture,
6262
bool is_wrapped);
6363

6464
// |Texture|
65-
void SetLabel(const std::string_view& label) override;
65+
void SetLabel(std::string_view label) override;
6666

6767
// |Texture|
6868
bool OnSetContents(const uint8_t* contents,

impeller/renderer/backend/metal/shader_library_mtl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ class ShaderLibraryMTL final : public ShaderLibrary {
3939
ShaderLibraryMTL(NSArray<id<MTLLibrary>>* libraries);
4040

4141
// |ShaderLibrary|
42-
std::shared_ptr<const ShaderFunction> GetFunction(
43-
const std::string_view& name,
44-
ShaderStage stage) override;
42+
std::shared_ptr<const ShaderFunction> GetFunction(std::string_view name,
43+
ShaderStage stage) override;
4544

4645
FML_DISALLOW_COPY_AND_ASSIGN(ShaderLibraryMTL);
4746
};

impeller/renderer/backend/metal/shader_library_mtl.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
}
2525

2626
std::shared_ptr<const ShaderFunction> ShaderLibraryMTL::GetFunction(
27-
const std::string_view& name,
27+
std::string_view name,
2828
ShaderStage stage) {
2929
if (!IsValid()) {
3030
return nullptr;

impeller/renderer/backend/metal/texture_mtl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class TextureMTL final : public Texture,
2727
bool is_valid_ = false;
2828

2929
// |Texture|
30-
void SetLabel(const std::string_view& label) override;
30+
void SetLabel(std::string_view label) override;
3131

3232
// |Texture|
3333
bool OnSetContents(const uint8_t* contents,

impeller/renderer/backend/metal/texture_mtl.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
TextureMTL::~TextureMTL() = default;
2828

29-
void TextureMTL::SetLabel(const std::string_view& label) {
29+
void TextureMTL::SetLabel(std::string_view label) {
3030
[texture_ setLabel:@(label.data())];
3131
}
3232

0 commit comments

Comments
 (0)