@@ -22,19 +22,27 @@ namespace o2::framework
2222
2323namespace
2424{
25- std::shared_ptr<arrow::ChunkedArray> GetColumnByNameCI (std::shared_ptr<arrow::Table> const & table, std::string const & key)
25+ // ASCII-only lowercase. Column labels are plain identifiers, so we deliberately
26+ // avoid the locale-aware std::tolower: it goes through the C locale facet on
27+ // every character and dominated getIndexFromLabel in profiles.
28+ constexpr inline char asciiToLower (char c)
2629{
27- auto const & fields = table->schema ()->fields ();
28- auto target = std::find_if (fields.begin (), fields.end (), [&key](std::shared_ptr<arrow::Field> const & field) {
29- return [](std::string_view const & s1, std::string_view const & s2) {
30- return std::ranges::equal (
31- s1, s2,
32- [](char c1, char c2) {
33- return std::tolower (static_cast <unsigned char >(c1)) == std::tolower (static_cast <unsigned char >(c2));
34- });
35- }(field->name (), key);
30+ return (c >= ' A' && c <= ' Z' ) ? static_cast <char >(c + 32 ) : c;
31+ }
32+
33+ arrow::ChunkedArray* getIndexFromLabel (arrow::Table* table, std::string_view label)
34+ {
35+ auto field = std::ranges::find_if (table->schema ()->fields (), [label](std::shared_ptr<arrow::Field> const & field) {
36+ std::string_view name = field->name ();
37+ return name == label ||
38+ std::ranges::equal (label, name, [](char c1, char c2){
39+ return asciiToLower (c1) == asciiToLower (c2);
40+ });
3641 });
37- return table->column (std::distance (fields.begin (), target));
42+ if (field == table->schema ()->fields ().end ()) {
43+ throw runtime_error_f (" Unable to find column with label %s." , label);
44+ }
45+ return table->column (std::distance (table->schema ()->fields ().begin (), field)).get ();
3846}
3947} // namespace
4048
@@ -119,7 +127,7 @@ arrow::Status ArrowTableSlicingCache::updateCacheEntry(int pos, std::shared_ptr<
119127 validateOrder (bindingsKeys[pos], table);
120128
121129 int maxValue = -1 ;
122- auto column = GetColumnByNameCI (table, k);
130+ auto column = getIndexFromLabel (table. get () , k);
123131
124132 // starting from the end, find the first positive value, in a sorted column it is the largest index
125133 for (auto iChunk = column->num_chunks () - 1 ; iChunk >= 0 ; --iChunk) {
@@ -164,7 +172,7 @@ arrow::Status ArrowTableSlicingCache::updateCacheEntry(int pos, std::shared_ptr<
164172 return arrow::Status::OK ();
165173}
166174
167- arrow::Status ArrowTableSlicingCache::updateCacheEntryUnsorted (int pos, const std::shared_ptr<arrow::Table>& table)
175+ arrow::Status ArrowTableSlicingCache::updateCacheEntryUnsorted (int pos, std::shared_ptr<arrow::Table> const & table)
168176{
169177 valuesUnsorted[pos].clear ();
170178 groups[pos].clear ();
@@ -175,7 +183,7 @@ arrow::Status ArrowTableSlicingCache::updateCacheEntryUnsorted(int pos, const st
175183 if (!e) {
176184 throw runtime_error_f (" Disabled unsorted cache %s/%s update requested" , b.c_str (), k.c_str ());
177185 }
178- auto column = GetColumnByNameCI (table, k);
186+ auto column = getIndexFromLabel (table. get () , k);
179187 auto row = 0 ;
180188 for (auto iChunk = 0 ; iChunk < column->num_chunks (); ++iChunk) {
181189 auto chunk = static_cast <arrow::NumericArray<arrow::Int32Type>>(column->chunk (iChunk)->data ());
@@ -283,16 +291,15 @@ void ArrowTableSlicingCache::validateOrder(Entry const& bindingKey, const std::s
283291 if (!enabled) {
284292 return ;
285293 }
286- auto column = o2::framework::GetColumnByNameCI (input, key);
287- auto array0 = static_cast <arrow::NumericArray<arrow::Int32Type>>(column->chunk (0 )->data ());
288- int32_t prev;
289- int32_t cur = array0.Value (0 );
294+ auto column = getIndexFromLabel (input.get (), key);
295+ auto array = static_cast <arrow::NumericArray<arrow::Int32Type>>(column->chunk (0 )->data ());
296+ int32_t cur = array.Value (0 );
290297 int32_t lastNeg = cur < 0 ? cur : 0 ;
291298 int32_t lastPos = cur < 0 ? -1 : cur;
292299 for (auto i = 0 ; i < column->num_chunks (); ++i) {
293- auto array = static_cast <arrow::NumericArray<arrow::Int32Type>>(column->chunk (i)->data ());
300+ array = static_cast <arrow::NumericArray<arrow::Int32Type>>(column->chunk (i)->data ());
294301 for (auto e = 0 ; e < array.length (); ++e) {
295- prev = cur;
302+ int32_t prev = cur;
296303 if (prev >= 0 ) {
297304 lastPos = prev;
298305 } else {
0 commit comments