Skip to content

Commit

Permalink
EZ const std:string -> string_view
Browse files Browse the repository at this point in the history
Summary:
PROBLEM
`RowType::containsChild()` takes a `string_view` , but if we want to get the index, we need to have a `std::string` .
There isn't any specific reason for mandating the `const std::string&` in the interface, especially when the `findChild` API also uses a StringPiece.

SOLUTION
Change to use `std::string_view`

Differential Revision: D69075102
  • Loading branch information
Gaurav Mogre authored and facebook-github-bot committed Feb 3, 2025
1 parent a8ea2c9 commit 36684c6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions velox/type/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ bool RowType::containsChild(std::string_view name) const {
return std::find(names_.begin(), names_.end(), name) != names_.end();
}

uint32_t RowType::getChildIdx(const std::string& name) const {
uint32_t RowType::getChildIdx(std::string_view name) const {
auto index = getChildIdxIfExists(name);
if (!index.has_value()) {
VELOX_USER_FAIL(makeFieldNotFoundErrorMessage(name, names_));
Expand All @@ -430,7 +430,7 @@ uint32_t RowType::getChildIdx(const std::string& name) const {
}

std::optional<uint32_t> RowType::getChildIdxIfExists(
const std::string& name) const {
std::string_view name) const {
for (uint32_t i = 0; i < names_.size(); i++) {
if (names_.at(i) == name) {
return i;
Expand Down
4 changes: 2 additions & 2 deletions velox/type/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -1026,9 +1026,9 @@ class RowType : public TypeBase<TypeKind::ROW> {

bool containsChild(std::string_view name) const;

uint32_t getChildIdx(const std::string& name) const;
uint32_t getChildIdx(std::string_view name) const;

std::optional<uint32_t> getChildIdxIfExists(const std::string& name) const;
std::optional<uint32_t> getChildIdxIfExists(std::string_view name) const;

const std::string& nameOf(uint32_t idx) const {
VELOX_CHECK_LT(idx, names_.size());
Expand Down

0 comments on commit 36684c6

Please sign in to comment.