8000 Take `std::string_view` instead of `const std::string&` in most places · Issue #105 · loot/libloot · GitHub
[go: up one dir, main page]

Skip to content

Take std::string_view instead of const std::string& in most places #105

Closed

Description

@Ortham

In some cases a string reference is needed (e.g. when checking if a string is in a map) or a null-terminated string is needed (e.g. when calling C APIs), so a const std::string& makes more sense, but otherwise it can mean an unnecessary copy of the string to create a std::string if the caller doesn't already have one.

I noticed this recently when writing the C++ wrapper for libloot-rs as its CXX wrapper returns many strings using its own equivalent of std::string_view, so I was having to create copies of the strings just to pass them into functions where they may just be read or may be copied again.

This impacts:

  • The ConditionalMetadata constructor
  • The File constructor
  • The Filename constructor
  • The Group constructor
  • The Location constructor
  • The MessageContent constructor
  • The Message constructor
  • The PluginCleaningData constructor
  • The PluginMetadata constructor
  • The Tag constructor
  • The Vertex constructor
  • PluginMetadata::SetGroup()
  • PluginMetadata::NameMatches()
  • SelectMessageContent()
  • DatabaseInterface::GetGroupsPath()
  • DatabaseInterface::GetPluginMetadata()
  • DatabaseInterface::GetPluginUserMetadata()
  • DatabaseInterface::DiscardPluginUserMetadata()
  • GameInterface::GetPlugin()
  • GameInterface::IsPluginActive()

Since there's an implicit conversion for std::string to std::string_view, this shouldn't require any consumer changes. It is a breaking change though.

Activity

  1. self-assigned this
    on Apr 1, 2025
  2. Ortham commented on Apr 29, 2025

    @Ortham
    MemberAuthor

    Done in fac0574.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0