Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
Thanks to small string optimization, storing a short string to std::string
is usually more efficient than referring it from std::string_view.
  • Loading branch information
rui314 committed Jul 30, 2023
1 parent f816c45 commit ba3fd65
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions elf/arch-riscv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ i64 riscv_resize_sections(Context<E> &ctx) {
// The following functions takes care of ISA strings.

struct Extn {
std::string_view name;
std::string name;
i64 major;
i64 minor;
};
Expand Down Expand Up @@ -1084,12 +1084,12 @@ static std::vector<Extn> merge_extensions(std::span<Extn> x, std::span<Extn> y)
}

static std::string to_string(std::span<Extn> v) {
std::string str = std::string(v[0].name) + std::to_string(v[0].major) +
"p" + std::to_string(v[0].minor);
std::string str = v[0].name + std::to_string(v[0].major) + "p" +
std::to_string(v[0].minor);

for (i64 i = 1; i < v.size(); i++)
str += "_" + std::string(v[i].name) + std::to_string(v[i].major) +
"p" + std::to_string(v[i].minor);
str += "_" + v[i].name + std::to_string(v[i].major) + "p" +
std::to_string(v[i].minor);
return str;
}

Expand Down

0 comments on commit ba3fd65

Please sign in to comment.