From 568667bef30c653392ba8d9a08b9de5056334a95 Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Sat, 7 Oct 2023 06:34:52 +0900 Subject: [PATCH] GH-38090: [C++][Emscripten] chunk_resolver: Suppress shorten-64-to-32 warnings We need explicit cast to use `int64_t` for `size_t` on Emscripten. Explicit casts. --- cpp/src/arrow/chunk_resolver.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cpp/src/arrow/chunk_resolver.h b/cpp/src/arrow/chunk_resolver.h index 818070ffe350a..f8008de159cc3 100644 --- a/cpp/src/arrow/chunk_resolver.h +++ b/cpp/src/arrow/chunk_resolver.h @@ -62,13 +62,16 @@ 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(offsets_[static_cast(cached_chunk)]) && + index < static_cast(offsets_[static_cast(cached_chunk + 1)])); if (ARROW_PREDICT_TRUE(cache_hit)) { - return {cached_chunk, index - offsets_[cached_chunk]}; + return {cached_chunk, + index - static_cast(offsets_[static_cast(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(offsets_[static_cast(chunk_index)])}; } protected: @@ -76,12 +79,12 @@ struct ARROW_EXPORT ChunkResolver { 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(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(index) >= offsets_[mid]) { + const size_t m = n >> 1; + const size_t mid = lo + m; + if (index >= offsets_[mid]) { lo = mid; n -= m; } else {