mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-11-13 22:06:55 +00:00
71e734b120
Add the option to calculate total size (inclusive size) by wrapping the existing iterator. This change provides a new iterator, `SizedIterator`, which wraps an existing iterator and adds a new field `size` to the output element. This is achieved with a two pass algorithm on the existing iterator: 1. Gather metadata for each element. This includes the total size up until that element and the range of elements that should be included in the size. 2. Return the result from the underlying iterator with the additional field. This algorithm is `O(N)` time on the number of elements in the iterator and `O(N)` time, storing 16 bytes per element. This isn't super expensive but is a lot more than the current algorithm which requires close to constant space. Because of this I've implemented it as a wrapper on the iterator rather than on by default, though it is now on in every one of our integration test cases. Test plan: - Added to the integration tests for full coverage.
63 lines
1.7 KiB
TOML
63 lines
1.7 KiB
TOML
definitions = '''
|
|
class Base {
|
|
int32_t base_int;
|
|
};
|
|
|
|
class Public : public Base {
|
|
int32_t public_int;
|
|
};
|
|
|
|
class Protected : protected Base {
|
|
int32_t protected_int;
|
|
};
|
|
|
|
class Private : private Base {
|
|
int32_t private_int;
|
|
};
|
|
'''
|
|
[cases]
|
|
[cases.public]
|
|
param_types = ["const Public&"]
|
|
setup = "return {};"
|
|
expect_json = '''[{
|
|
"staticSize":8,
|
|
"exclusiveSize":0,
|
|
"size":8,
|
|
"members":[
|
|
{"name":"base_int", "staticSize":4, "exclusiveSize":4, "size":4, "typeName": "int32_t"},
|
|
{"name":"public_int", "staticSize":4, "exclusiveSize":4, "size":4, "typeName": "int32_t"}
|
|
]}]'''
|
|
[cases.protected]
|
|
param_types = ["const Protected&"]
|
|
setup = "return {};"
|
|
expect_json = '''[{
|
|
"staticSize":8,
|
|
"exclusiveSize":0,
|
|
"size":8,
|
|
"members":[
|
|
{"name":"base_int", "staticSize":4, "exclusiveSize":4, "size":4, "typeName": "int32_t"},
|
|
{"name":"protected_int", "staticSize":4, "exclusiveSize":4, "size":4, "typeName": "int32_t"}
|
|
]}]'''
|
|
[cases.private]
|
|
param_types = ["const Private&"]
|
|
setup = "return {};"
|
|
expect_json = '''[{
|
|
"staticSize":8,
|
|
"exclusiveSize":0,
|
|
"size":8,
|
|
"members":[
|
|
{"name":"base_int", "staticSize":4, "exclusiveSize":4, "size":4, "typeName": "int32_t"},
|
|
{"name":"private_int", "staticSize":4, "exclusiveSize":4, "size":4, "typeName": "int32_t"}
|
|
]}]'''
|
|
[cases.public_as_base]
|
|
param_types = ["const Base&"]
|
|
arg_types = ["Public"]
|
|
setup = "return {};"
|
|
expect_json = '''[{
|
|
"staticSize":4,
|
|
"exclusiveSize":0,
|
|
"size":4,
|
|
"members":[
|
|
{"name":"base_int", "staticSize":4, "exclusiveSize":4, "size":4, "typeName": "int32_t"}
|
|
]}]'''
|