Skip to content

Commit

Permalink
apacheGH-38090: [C++][Emscripten] chunk_resolver: Suppress shorten-64…
Browse files Browse the repository at this point in the history
…-to-32 warnings

We need explicit cast to use `int64_t` for `size_t` on Emscripten.

Explicit casts.
  • Loading branch information
kou committed Oct 6, 2023
1 parent 3697bcd commit 568667b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cpp/src/arrow/chunk_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,29 @@ struct ARROW_EXPORT ChunkResolver {
}
const auto cached_chunk = cached_chunk_.load();
const bool cache_hit =
(index >= offsets_[cached_chunk] && index < offsets_[cached_chunk + 1]);
(index >= static_cast<int64_t>(offsets_[static_cast<size_t>(cached_chunk)]) &&
index < static_cast<int64_t>(offsets_[static_cast<size_t>(cached_chunk + 1)]));
if (ARROW_PREDICT_TRUE(cache_hit)) {
return {cached_chunk, index - offsets_[cached_chunk]};
return {cached_chunk,
index - static_cast<int64_t>(offsets_[static_cast<size_t>(cached_chunk)])};
}
auto chunk_index = Bisect(index);
cached_chunk_.store(chunk_index);
return {chunk_index, index - offsets_[chunk_index]};
return {chunk_index,
index - static_cast<int64_t>(offsets_[static_cast<size_t>(chunk_index)])};
}

protected:
// Find the chunk index corresponding to a value index using binary search
inline int64_t Bisect(const int64_t index) const {
// Like std::upper_bound(), but hand-written as it can help the compiler.
// Search [lo, lo + n)
int64_t lo = 0;
auto n = static_cast<int64_t>(offsets_.size());
size_t lo = 0;
auto n = offsets_.size();
while (n > 1) {
const int64_t m = n >> 1;
const int64_t mid = lo + m;
if (static_cast<int64_t>(index) >= offsets_[mid]) {
const size_t m = n >> 1;
const size_t mid = lo + m;
if (index >= offsets_[mid]) {
lo = mid;
n -= m;
} else {
Expand Down

0 comments on commit 568667b

Please sign in to comment.