Skip to content

Commit b8be78a

Browse files
committed
DPL: improve getIndexFromLabel
Avoids extra string creation.
1 parent 7b2c021 commit b8be78a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,7 @@ auto select(T const& t, framework::expressions::Filter const& f)
16261626
return Filtered<T>({t.asArrowTable()}, selectionToVector(framework::expressions::createSelection(t.asArrowTable(), f)));
16271627
}
16281628

1629-
arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, const char* label);
1629+
arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, std::string_view label);
16301630

16311631
template <typename D, typename O, typename IP, typename... C>
16321632
consteval auto base_iter(framework::pack<C...>&&) -> TableIterator<D, O, IP, C...>

Framework/Core/src/ASoA.cxx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,19 @@ std::shared_ptr<arrow::Table> ArrowHelpers::concatTables(std::vector<std::shared
123123
return result;
124124
}
125125

126-
arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, const char* label)
126+
arrow::ChunkedArray* getIndexFromLabel(arrow::Table* table, std::string_view label)
127127
{
128128
auto field = std::find_if(table->schema()->fields().begin(), table->schema()->fields().end(), [&](std::shared_ptr<arrow::Field> const& f) {
129-
return o2::framework::strToUpper(label) == o2::framework::strToUpper(std::string{f->name()});
129+
auto caseInsensitiveCompare = [](const std::string_view& str1, const std::string& str2) {
130+
return std::ranges::equal(
131+
str1, str2,
132+
[](char c1, char c2) {
133+
return std::tolower(static_cast<unsigned char>(c1)) ==
134+
std::tolower(static_cast<unsigned char>(c2));
135+
});
136+
};
137+
138+
return caseInsensitiveCompare(label, f->name());
130139
});
131140
if (field == table->schema()->fields().end()) {
132141
o2::framework::throw_error(o2::framework::runtime_error_f("Unable to find column with label %s", label));

0 commit comments

Comments
 (0)