Skip to content

Commit fb5a7b0

Browse files
Mohammed Dasmeta-codesync[bot]
authored andcommitted
Add visitAllocationClasses to TypeToMaskAdapter when using F14 Maps
Summary: When using a `Mask` field in a Thrift struct that uses the plugin: thrift_plugin_allocated, it fails to compile. This is because we need to define the traits somewhere as: ``` template <typename T> struct allocated_size_traits< apache::thrift::protocol::detail::ValidatingTypeMap<T>> { static std::size_t allocated_bytes( const apache::thrift::protocol::detail::ValidatingTypeMap<T>& container, unsigned flags = 0U) { auto result = bytesAllocatedByRange(container.begin(), container.end(), flags); container.visitAllocationClasses( [&result](size_t const size, size_t const count) { result += count * bytesAllocatedForSize(size); }); return result; } }; ``` TypeToMaskAdapter is a wrapper around F14Map (or std::map) [with private internal `map_` field] and other methods just forward to map_. So, e can define the above trait as similarly done for F14Map, but we need to add a public method `visitAllocationClasses` similar to F14Map. Reviewed By: iahs Differential Revision: D95068786 fbshipit-source-id: 0e4adde79d633c88ae11338c10928378af855431
1 parent 2fb78d7 commit fb5a7b0

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

third-party/thrift/src/thrift/lib/thrift/TypeToMaskAdapter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class ValidatingTypeMap {
3232
#if FOLLY_F14_VECTOR_INTRINSICS_AVAILABLE
3333
using map_type = folly::F14VectorMap<type::Type, Mask>;
3434
void reserve(std::size_t n) { map_.reserve(n); }
35+
template <typename V>
36+
void visitAllocationClasses(V&& visitor) const {
37+
return map_.visitAllocationClasses(std::forward<V>(visitor));
38+
}
3539
#else
3640
// f14 map is not available in some platforms. Default to std::map which is
3741
// able to handle incomplete types

0 commit comments

Comments
 (0)