Commit e2db8003 authored by Xiao Shi's avatar Xiao Shi Committed by Facebook Github Bot

explicitly convert to `InternalSizeType` in F14

Summary:
For F14Vector containers, we assume that the size could fit in `uint32_t`,
i.e., the `InternalSizeType`. This diff fixes where we implicitly convert
(shorten) a `size_t` to `InternalSizeType`.

Reviewed By: nbronson

fbshipit-source-id: e970071dbde6394262a555facc8e2a24c6007f68
parent e66fb34c
...@@ -1115,7 +1115,8 @@ class VectorContainerPolicy : public BasePolicy< ...@@ -1115,7 +1115,8 @@ class VectorContainerPolicy : public BasePolicy<
template <typename... Args> template <typename... Args>
void constructValueAtItem(std::size_t size, Item* itemAddr, Args&&... args) { void constructValueAtItem(std::size_t size, Item* itemAddr, Args&&... args) {
Alloc& a = this->alloc(); Alloc& a = this->alloc();
*itemAddr = size; FOLLY_SAFE_DCHECK(size < std::numeric_limits<InternalSizeType>::max(), "");
*itemAddr = static_cast<InternalSizeType>(size);
auto dst = std::addressof(values_[size]); auto dst = std::addressof(values_[size]);
// TODO(T31574848): clean up assume-s used to optimize placement new // TODO(T31574848): clean up assume-s used to optimize placement new
assume(dst != nullptr); assume(dst != nullptr);
......
...@@ -1320,7 +1320,7 @@ class F14Table : public Policy { ...@@ -1320,7 +1320,7 @@ class F14Table : public Policy {
return size() == 0; return size() == 0;
} }
std::size_t size() const noexcept { typename Policy::InternalSizeType size() const noexcept {
return sizeAndPackedBegin_.size_; return sizeAndPackedBegin_.size_;
} }
...@@ -1810,7 +1810,13 @@ class F14Table : public Policy { ...@@ -1810,7 +1810,13 @@ class F14Table : public Policy {
rawAllocation); rawAllocation);
chunks_ = chunks_ =
initializeChunks(rawAllocation, newChunkCount, newMaxSizeWithoutRehash); initializeChunks(rawAllocation, newChunkCount, newMaxSizeWithoutRehash);
chunkMask_ = newChunkCount - 1;
FOLLY_SAFE_DCHECK(
newChunkCount <
std::numeric_limits<typename Policy::InternalSizeType>::max(),
"");
chunkMask_ =
static_cast<typename Policy::InternalSizeType>(newChunkCount - 1);
bool success = false; bool success = false;
SCOPE_EXIT { SCOPE_EXIT {
...@@ -1829,7 +1835,12 @@ class F14Table : public Policy { ...@@ -1829,7 +1835,12 @@ class F14Table : public Policy {
finishedAllocSize = finishedAllocSize =
chunkAllocSize(newChunkCount, newMaxSizeWithoutRehash); chunkAllocSize(newChunkCount, newMaxSizeWithoutRehash);
chunks_ = origChunks; chunks_ = origChunks;
chunkMask_ = origChunkCount - 1; FOLLY_SAFE_DCHECK(
origChunkCount <
std::numeric_limits<typename Policy::InternalSizeType>::max(),
"");
chunkMask_ =
static_cast<typename Policy::InternalSizeType>(origChunkCount - 1);
} }
this->afterRehash( this->afterRehash(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment