mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-09-19 19:19:05 +01:00
08e2faa90e
`std::list` has per element overhead for the individual heap allocations. This was already calculated in the container implementation but not used. Allocate the overhead of each element in the `std::list` to the `std::list` itself as with other sequential containers. Test Plan: - CI - Updated test cases
75 lines
1.8 KiB
TOML
75 lines
1.8 KiB
TOML
[info]
|
|
type_name = "std::list"
|
|
stub_template_params = [1]
|
|
ctype = "LIST_TYPE"
|
|
header = "list"
|
|
|
|
# Old:
|
|
typeName = "std::list<"
|
|
ns = ["namespace std"]
|
|
numTemplateParams = 1
|
|
replaceTemplateParamIndex = []
|
|
allocatorIndex = 1
|
|
|
|
[codegen]
|
|
decl = """
|
|
template<typename T, typename Allocator>
|
|
void getSizeType(const %1%<T, Allocator> &container, size_t& returnArg);
|
|
"""
|
|
|
|
func = """
|
|
template<typename T, typename Allocator>
|
|
void getSizeType(const %1%<T, Allocator> &container, size_t& returnArg)
|
|
{
|
|
SAVE_SIZE(sizeof(%1%<T>));
|
|
|
|
SAVE_DATA((uintptr_t)&container);
|
|
SAVE_DATA((uintptr_t)container.size());
|
|
|
|
// The double ampersand is needed otherwise this loop doesn't work with vector<bool>
|
|
for (auto&& it: container) {
|
|
getSizeType(it, returnArg);
|
|
}
|
|
}
|
|
"""
|
|
|
|
traversal_func = """
|
|
auto tail = returnArg.write((uintptr_t)&container)
|
|
.write(container.size());
|
|
|
|
for (auto&& it : container) {
|
|
tail = tail.delegate([&ctx, &it](auto ret) {
|
|
return OIInternal::getSizeType<Ctx>(ctx, it, ret);
|
|
});
|
|
}
|
|
|
|
return tail.finish();
|
|
"""
|
|
|
|
[[codegen.processor]]
|
|
type = "types::st::VarInt<DB>"
|
|
func = """
|
|
el.pointer = std::get<ParsedData::VarInt>(d.val).value;
|
|
"""
|
|
|
|
[[codegen.processor]]
|
|
type = "types::st::List<DB, typename TypeHandler<Ctx, T0>::type>"
|
|
func = """
|
|
#ifdef __GLIBCXX__
|
|
static constexpr size_t element_size = sizeof(std::_List_node<T0>);
|
|
#else
|
|
static_assert(false && "No known element_size for list. See types/cxx11_list_type.toml");
|
|
#endif
|
|
|
|
static constexpr auto childField = make_field<Ctx, T0>("[]");
|
|
|
|
auto list = std::get<ParsedData::List>(d.val);
|
|
el.container_stats.emplace(result::Element::ContainerStats{
|
|
.capacity = list.length,
|
|
.length = list.length,
|
|
});
|
|
el.exclusive_size += el.container_stats->length * (element_size - sizeof(T0));
|
|
|
|
stack_ins(inst::Repeat{ list.length, childField });
|
|
"""
|