Skip to content

Commit 0534324

Browse files
committed
improve chunk handling in column iterator
1 parent 0dc2603 commit 0534324

File tree

1 file changed

+41
-50
lines changed
  • Framework/Core/include/Framework

1 file changed

+41
-50
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,7 @@ struct Binding {
381381
{
382382
ptr = table;
383383
hash = o2::framework::TypeIdHelpers::uniqueId<T>();
384-
if constexpr (framework::base_of_template<soa::Table, T>) {
385-
refs = std::span{T::originals};
386-
}
384+
refs = std::span{T::originals};
387385
}
388386

389387
template <typename T>
@@ -552,53 +550,33 @@ class ColumnIterator : ChunkingPolicy
552550
}
553551

554552
decltype(auto) operator*() const
553+
requires std::same_as<bool, std::decay_t<T>>
555554
{
556-
if constexpr (ChunkingPolicy::chunked) {
557-
if constexpr (std::same_as<arrow_array_for_t<T>, arrow::ListArray>) {
558-
auto list = std::static_pointer_cast<arrow::ListArray>(mColumn->chunk(mCurrentChunk));
559-
if (O2_BUILTIN_UNLIKELY(*mCurrentPos - mFirstIndex >= list->length())) {
560-
nextChunk();
561-
}
562-
} else {
563-
if (O2_BUILTIN_UNLIKELY(((mCurrent + (*mCurrentPos >> SCALE_FACTOR)) >= mLast))) {
564-
nextChunk();
565-
}
566-
}
567-
}
568-
if constexpr (std::same_as<bool, std::decay_t<T>>) {
569-
// FIXME: check if shifting the masked bit to the first position is better than != 0
570-
return (*(mCurrent - (mOffset >> SCALE_FACTOR) + ((*mCurrentPos + mOffset) >> SCALE_FACTOR)) & (1 << ((*mCurrentPos + mOffset) & 0x7))) != 0;
571-
} else if constexpr (std::same_as<arrow_array_for_t<T>, arrow::ListArray>) {
572-
auto list = std::static_pointer_cast<arrow::ListArray>(mColumn->chunk(mCurrentChunk));
573-
auto offset = list->value_offset(*mCurrentPos - mFirstIndex);
574-
auto length = list->value_length(*mCurrentPos - mFirstIndex);
575-
return gsl::span{mCurrent + mFirstIndex + offset, mCurrent + mFirstIndex + (offset + length)};
576-
} else {
577-
return *(mCurrent + (*mCurrentPos >> SCALE_FACTOR));
578-
}
555+
checkSkipChunk();
556+
return (*(mCurrent - (mOffset >> SCALE_FACTOR) + ((*mCurrentPos + mOffset) >> SCALE_FACTOR)) & (1 << ((*mCurrentPos + mOffset) & 0x7))) != 0;
579557
}
580558

581-
// Move to the chunk which containts element pos
582-
ColumnIterator<T>& moveToPos()
559+
decltype(auto) operator*() const
560+
requires((!std::same_as<bool, std::decay_t<T>>) && std::same_as<arrow_array_for_t<T>, arrow::ListArray>)
583561
{
584-
// If we get outside range of the current chunk, go to the next.
585-
if constexpr (ChunkingPolicy::chunked) {
586-
while (O2_BUILTIN_UNLIKELY((mCurrent + (*mCurrentPos >> SCALE_FACTOR)) >= mLast)) {
587-
nextChunk();
588-
}
589-
}
590-
return *this;
562+
checkSkipChunk();
563+
auto list = std::static_pointer_cast<arrow::ListArray>(mColumn->chunk(mCurrentChunk));
564+
auto offset = list->value_offset(*mCurrentPos - mFirstIndex);
565+
auto length = list->value_length(*mCurrentPos - mFirstIndex);
566+
return gsl::span{mCurrent + mFirstIndex + offset, mCurrent + mFirstIndex + (offset + length)};
567+
}
568+
569+
decltype(auto) operator*() const
570+
requires((!std::same_as<bool, std::decay_t<T>>) && !std::same_as<arrow_array_for_t<T>, arrow::ListArray>)
571+
{
572+
checkSkipChunk();
573+
return *(mCurrent + (*mCurrentPos >> SCALE_FACTOR));
591574
}
592575

593576
// Move to the chunk which containts element pos
594-
ColumnIterator<T>& checkNextChunk()
577+
ColumnIterator<T>& moveToPos()
595578
{
596-
if constexpr (ChunkingPolicy::chunked) {
597-
if (O2_BUILTIN_LIKELY((mCurrent + (*mCurrentPos >> SCALE_FACTOR)) <= mLast)) {
598-
return *this;
599-
}
600-
nextChunk();
601-
}
579+
checkSkipChunk();
602580
return *this;
603581
}
604582

@@ -611,6 +589,27 @@ class ColumnIterator : ChunkingPolicy
611589
mutable int mOffset;
612590

613591
private:
592+
void checkSkipChunk()
593+
requires((ChunkingPolicy::chunked == true) && std::same_as<arrow_array_for_t<T>, arrow::ListArray>)
594+
{
595+
auto list = std::static_pointer_cast<arrow::ListArray>(mColumn->chunk(mCurrentChunk));
596+
if (O2_BUILTIN_UNLIKELY(*mCurrentPos - mFirstIndex >= list->length())) {
597+
nextChunk();
598+
}
599+
}
600+
601+
void checkSkipChunk()
602+
requires((ChunkingPolicy::chunked == true) && !std::same_as<arrow_array_for_t<T>, arrow::ListArray>)
603+
{
604+
if (O2_BUILTIN_UNLIKELY(((mCurrent + (*mCurrentPos >> SCALE_FACTOR)) >= mLast))) {
605+
nextChunk();
606+
}
607+
}
608+
609+
void checkSkipChunk()
610+
requires(ChunkingPolicy::chunked == false)
611+
{
612+
}
614613
/// get pointer to mCurrentChunk chunk
615614
auto getCurrentArray() const
616615
{
@@ -1161,14 +1160,6 @@ struct TableIterator : IP, C... {
11611160
}
11621161

11631162
private:
1164-
/// Helper to move to the correct chunk, if needed.
1165-
/// FIXME: not needed?
1166-
template <typename... PC>
1167-
void checkNextChunk(framework::pack<PC...>)
1168-
{
1169-
(PC::mColumnIterator.checkNextChunk(), ...);
1170-
}
1171-
11721163
/// Helper to move at the end of columns which actually have an iterator.
11731164
template <typename... PC>
11741165
void doMoveToEnd(framework::pack<PC...>)

0 commit comments

Comments
 (0)