Skip to content

Commit

Permalink
Remove unneeded string copy construction in StringIdMap
Browse files Browse the repository at this point in the history
A variable of type `std::string_view` can be directly assigned to a
variable of type `std::string`. There is no need to construct a
temporary variable first and then assign the value. The latter will
cause a redundant copy construction.
  • Loading branch information
lingbin committed Feb 23, 2024
1 parent 0d02c8f commit be21d88
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion velox/common/caching/StringIdMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ uint64_t StringIdMap::makeId(std::string_view string) {
return it->second;
}
Entry entry;
entry.string = std::string(string);
entry.string = string;
// Check that we do not use an id twice. In practice this never
// happens because the int64 counter would have to wrap around for
// this. Even if this happened, the time spent in the loop would
Expand Down

0 comments on commit be21d88

Please sign in to comment.