2022-12-19 14:37:51 +00:00
|
|
|
[info]
|
2023-05-23 22:26:38 +01:00
|
|
|
type_name = "std::basic_string"
|
TypeGraph: Fix std::string container
std::basic_string takes three template parameters:
1. CharT
2. Traits
3. Allocator
The Traits parameter was causing issues, as it requires a type which
exposes certain things, e.g. `Traits::value_type`.
We have a few options to resolve this:
1. Remove this parameter, as we do for allocators
Cons: removing a template parameter doesn't work if other
parameters appear after it
2. Stub this parameter, as we do for hashers/comparators
Cons: we need to hardcode an implementation that satisfies the
`Traits::value_type` requirements
3. Leave the parameter as-is
Cons: will not work if a non-standard Traits is used
By using the real implementation of this Traits parameter
(normally `std::char_traits<CharT>`), we get one that we know will
work as long as it is defined in a stdlib header.
Option 3 is what we use in this patch. Instead of adding more
configuration options to the container TOML file format (e.g.
`params_to_keep = [1]`), we add `std::char_traits` as a dummy
container type. Now, whenever `std::char_traits` appears, it will be
left as-is, i.e. not removed, replaced or reverse-engineered.
This is the same approach previously used for Thrift's isset_bitset.
2023-05-25 17:06:45 +01:00
|
|
|
stub_template_params = [2]
|
2022-12-19 14:37:51 +00:00
|
|
|
ctype = "STRING_TYPE"
|
|
|
|
header = "string"
|
2023-05-23 22:26:38 +01:00
|
|
|
|
|
|
|
# Old:
|
|
|
|
typeName = "std::basic_string<"
|
2022-12-19 14:37:51 +00:00
|
|
|
ns = ["namespace std"]
|
2023-05-23 22:26:38 +01:00
|
|
|
numTemplateParams = 1
|
2022-12-19 14:37:51 +00:00
|
|
|
replaceTemplateParamIndex = []
|
|
|
|
|
|
|
|
[codegen]
|
|
|
|
decl = """
|
2023-05-31 14:49:47 +01:00
|
|
|
template<typename T, typename Traits, typename Allocator>
|
|
|
|
void getSizeType(const %1%<T, Traits, Allocator> &container, size_t& returnArg);
|
2022-12-19 14:37:51 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
func = """
|
2023-05-31 14:49:47 +01:00
|
|
|
template<typename T, typename Traits, typename Allocator>
|
|
|
|
void getSizeType(const %1%<T, Traits, Allocator> &container, size_t& returnArg)
|
2022-12-19 14:37:51 +00:00
|
|
|
{
|
|
|
|
SAVE_SIZE(sizeof(%1%<T>));
|
|
|
|
|
2023-05-23 22:26:38 +01:00
|
|
|
SAVE_DATA((uintptr_t)container.capacity());
|
|
|
|
SAVE_DATA((uintptr_t)container.size());
|
2022-12-19 14:37:51 +00:00
|
|
|
|
|
|
|
// Test for small string optimisation - whether the underlying string is
|
|
|
|
// contained within the string object.
|
|
|
|
SAVE_SIZE(
|
2023-05-23 22:26:38 +01:00
|
|
|
((uintptr_t)container.data() < (uintptr_t)(&container + sizeof(%1%<T>)))
|
2022-12-19 14:37:51 +00:00
|
|
|
&&
|
2023-05-23 22:26:38 +01:00
|
|
|
((uintptr_t)container.data() >= (uintptr_t)&container)
|
|
|
|
? 0 : (container.capacity() * sizeof(T))
|
2022-12-19 14:37:51 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
"""
|
2023-12-19 19:57:44 +00:00
|
|
|
|
|
|
|
traversal_func = """
|
|
|
|
bool sso = ((uintptr_t)container.data() <
|
|
|
|
(uintptr_t)(&container + sizeof(std::__cxx11::basic_string<T0>))) &&
|
|
|
|
((uintptr_t)container.data() >= (uintptr_t)&container);
|
|
|
|
|
|
|
|
return returnArg.write(container.capacity())
|
|
|
|
.write(sso)
|
|
|
|
.write(container.size());
|
|
|
|
"""
|
|
|
|
|
|
|
|
[[codegen.processor]]
|
|
|
|
type = "types::st::VarInt<DB>"
|
|
|
|
func = """
|
|
|
|
uint64_t capacity = std::get<ParsedData::VarInt>(d.val).value;
|
|
|
|
el.container_stats.emplace(result::Element::ContainerStats { .capacity = capacity });
|
|
|
|
"""
|
|
|
|
|
|
|
|
[[codegen.processor]]
|
|
|
|
type = "types::st::VarInt<DB>"
|
|
|
|
func = """
|
|
|
|
bool sso = std::get<ParsedData::VarInt>(d.val).value;
|
|
|
|
if (!sso)
|
|
|
|
el.exclusive_size += el.container_stats->capacity * sizeof(T0);
|
|
|
|
"""
|
|
|
|
|
|
|
|
[[codegen.processor]]
|
|
|
|
type = "types::st::VarInt<DB>"
|
|
|
|
func = """
|
|
|
|
el.container_stats->length = std::get<ParsedData::VarInt>(d.val).value;
|
|
|
|
"""
|