mirror of
https://github.com/JakeHillion/object-introspection.git
synced 2024-09-19 19:19:05 +01: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.
114 lines
2.9 KiB
TOML
114 lines
2.9 KiB
TOML
definitions = '''
|
|
struct Foo {
|
|
int *a;
|
|
bool b;
|
|
long c;
|
|
};
|
|
|
|
struct Bar {
|
|
int *a;
|
|
bool b;
|
|
long c;
|
|
Foo d;
|
|
};
|
|
|
|
/* The names generated for parent's padding use their own index,
|
|
* which can conflict with the child's generated name.
|
|
* We must ensure there are no such conflicts, even across multiple parents.
|
|
*/
|
|
struct PaddedGrandParentA {
|
|
bool x;
|
|
short y;
|
|
};
|
|
|
|
struct PaddedGrandParentB {
|
|
bool x;
|
|
int y;
|
|
};
|
|
|
|
struct PaddedParentA : public PaddedGrandParentA {
|
|
bool a;
|
|
int b;
|
|
short c;
|
|
};
|
|
|
|
struct PaddedParentB : public PaddedGrandParentA, public PaddedGrandParentB {
|
|
bool a;
|
|
long b;
|
|
};
|
|
|
|
/* Create lots of padding holes so there is a colision between the child and
|
|
* its parent generated padding names.
|
|
*/
|
|
struct PaddedChild : public PaddedParentA, public PaddedParentB {
|
|
bool a;
|
|
long long b;
|
|
bool c; short d;
|
|
bool e; short f;
|
|
bool g; short h;
|
|
bool i; short j;
|
|
bool k; short l;
|
|
bool m; short n;
|
|
bool o; short p;
|
|
bool q; short r;
|
|
bool s; short t;
|
|
bool u; short v;
|
|
bool w; short x;
|
|
bool y; short z;
|
|
};
|
|
'''
|
|
|
|
[cases]
|
|
[cases.bool_padding]
|
|
param_types = ["const Foo&"]
|
|
setup = "return Foo{0, false, 0};"
|
|
expect_json = '''[{
|
|
"staticSize":24,
|
|
"dynamicSize":0,
|
|
"exclusiveSize": 7,
|
|
"members":[
|
|
{ "name":"a", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8 },
|
|
{ "name":"b", "staticSize":1, "dynamicSize":0, "exclusiveSize":1, "size":1 },
|
|
{ "name":"c", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8 }
|
|
]}]'''
|
|
|
|
[cases.nested_padding]
|
|
param_types = ["const Bar&"]
|
|
setup = "return Bar{0, false, 0, Foo { 0, false, 0 }};"
|
|
expect_json = '''[{
|
|
"staticSize":48,
|
|
"dynamicSize":0,
|
|
"exclusiveSize":7,
|
|
"size":48,
|
|
"members":[
|
|
{ "name":"a", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8 },
|
|
{ "name":"b", "staticSize":1, "dynamicSize":0, "exclusiveSize":1, "size":1 },
|
|
{ "name":"c", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8 },
|
|
{
|
|
"name":"d",
|
|
"staticSize":24,
|
|
"dynamicSize":0,
|
|
"exclusiveSize":7,
|
|
"size":24,
|
|
"members": [
|
|
{ "name":"a", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8 },
|
|
{ "name":"b", "staticSize":1, "dynamicSize":0, "exclusiveSize":1, "size":1 },
|
|
{ "name":"c", "staticSize":8, "dynamicSize":0, "exclusiveSize":8, "size":8 }
|
|
]}
|
|
]}]'''
|
|
|
|
[cases.parent_padding]
|
|
oid_skip = 'calculating incorrectly'
|
|
param_types = ["const PaddedChild&"]
|
|
setup = "return PaddedChild{};"
|
|
expect_json = '''[{
|
|
"staticSize": 104,
|
|
"dynamicSize": 0,
|
|
"paddingSavingsSize": 19
|
|
}]'''
|
|
expect_json_v2 = '''[{
|
|
"staticSize": 104,
|
|
"exclusiveSize": 32,
|
|
"size": 104
|
|
}]'''
|