Global Metrics
path: .metrics.nargs.average
old: 1.5128205128205128
new: 2.0
path: .metrics.nargs.sum
old: 59.0
new: 26.0
path: .metrics.cognitive.sum
old: 160.0
new: 9.0
path: .metrics.cognitive.average
old: 4.102564102564102
new: 0.6923076923076923
path: .metrics.cyclomatic.average
old: 6.0476190476190474
new: 1.6428571428571428
path: .metrics.cyclomatic.sum
old: 254.0
new: 23.0
path: .metrics.loc.blank
old: 141.0
new: 50.0
path: .metrics.loc.cloc
old: 165.0
new: 62.0
path: .metrics.loc.sloc
old: 1135.0
new: 310.0
path: .metrics.loc.ploc
old: 829.0
new: 198.0
path: .metrics.loc.lloc
old: 375.0
new: 86.0
path: .metrics.halstead.length
old: 4261.0
new: 1306.0
path: .metrics.halstead.time
old: 108635.26180757231
new: 30243.312664972986
path: .metrics.halstead.purity_ratio
old: 1.162666123643572
new: 0.4849689063245088
path: .metrics.halstead.N1
old: 2482.0
new: 744.0
path: .metrics.halstead.effort
old: 1955434.712536302
new: 544379.6279695136
path: .metrics.halstead.bugs
old: 5.212438680073819
new: 2.2223544219873395
path: .metrics.halstead.level
old: 0.019898819561551435
new: 0.01610788537179247
path: .metrics.halstead.N2
old: 1779.0
new: 562.0
path: .metrics.halstead.estimated_program_length
old: 4954.120352845261
new: 633.3693916598086
path: .metrics.halstead.n1
old: 30.0
new: 19.0
path: .metrics.halstead.n2
old: 531.0
new: 86.0
path: .metrics.halstead.vocabulary
old: 561.0
new: 105.0
path: .metrics.halstead.difficulty
old: 50.25423728813559
new: 62.08139534883721
path: .metrics.halstead.volume
old: 38910.84250915407
new: 8768.804646071956
path: .metrics.nexits.average
old: 2.9743589743589745
new: 0.0
path: .metrics.nexits.sum
old: 116.0
new: 0.0
path: .metrics.mi.mi_original
old: -56.33603120088797
new: 25.566958746975445
path: .metrics.mi.mi_visual_studio
old: 0.0
new: 14.951437863728328
path: .metrics.mi.mi_sei
old: -103.26817092457038
new: -4.538180097985652
path: .metrics.nom.functions
old: 39.0
new: 13.0
path: .metrics.nom.total
old: 39.0
new: 13.0
Spaces Data
Minimal test - lines (67, 74)
path: .spaces[4].metrics.halstead.level
old: 0.08627450980392157
new: 0.2222222222222222
path: .spaces[4].metrics.halstead.time
old: 278.42949617054734
new: 30.0
path: .spaces[4].metrics.halstead.length
old: 83.0
new: 30.0
path: .spaces[4].metrics.halstead.purity_ratio
old: 1.888082584869257
new: 1.6243018651066852
path: .spaces[4].metrics.halstead.volume
old: 432.38462934720286
new: 120.0
path: .spaces[4].metrics.halstead.n1
old: 15.0
new: 6.0
path: .spaces[4].metrics.halstead.N1
old: 49.0
new: 15.0
path: .spaces[4].metrics.halstead.vocabulary
old: 37.0
new: 16.0
path: .spaces[4].metrics.halstead.N2
old: 34.0
new: 15.0
path: .spaces[4].metrics.halstead.estimated_program_length
old: 156.71085454414833
new: 48.72905595320056
path: .spaces[4].metrics.halstead.bugs
old: 0.09761964928073769
new: 0.022104188991842317
path: .spaces[4].metrics.halstead.n2
old: 22.0
new: 10.0
path: .spaces[4].metrics.halstead.difficulty
old: 11.590909090909092
new: 4.5
path: .spaces[4].metrics.halstead.effort
old: 5011.730931069852
new: 540.0
path: .spaces[4].metrics.mi.mi_original
old: 93.83362190298604
new: 112.18808996232003
path: .spaces[4].metrics.mi.mi_visual_studio
old: 54.873463101161434
new: 65.60707015340354
path: .spaces[4].metrics.mi.mi_sei
old: 59.97790857428866
new: 121.22556242600818
path: .spaces[4].metrics.cyclomatic.average
old: 3.0
new: 1.0
path: .spaces[4].metrics.cyclomatic.sum
old: 3.0
new: 1.0
path: .spaces[4].metrics.loc.cloc
old: 0.0
new: 2.0
path: .spaces[4].metrics.loc.ploc
old: 14.0
new: 6.0
path: .spaces[4].metrics.loc.lloc
old: 6.0
new: 0.0
path: .spaces[4].metrics.loc.blank
old: 2.0
new: 0.0
path: .spaces[4].metrics.loc.sloc
old: 16.0
new: 8.0
path: .spaces[4].metrics.cognitive.sum
old: 3.0
new: 0.0
path: .spaces[4].metrics.cognitive.average
old: 3.0
new: 0.0
path: .spaces[4].metrics.nargs.average
old: 3.0
new: 2.0
path: .spaces[4].metrics.nargs.sum
old: 3.0
new: 2.0
path: .spaces[4].metrics.nexits.average
old: 2.0
new: 0.0
path: .spaces[4].metrics.nexits.sum
old: 2.0
new: 0.0
Code
TEST(ArenaAllocator, BadAlignment)
{
// This test causes build failures by triggering the static assert enforcing
// a power-of-two alignment.
ArenaAllocator<256, 3> a;
ArenaAllocator<256, 7> b;
ArenaAllocator<256, 17> c;
}
Minimal test - lines (97, 104)
path: .spaces[6].metrics.nargs.average
old: 0.0
new: 2.0
path: .spaces[6].metrics.nargs.sum
old: 0.0
new: 2.0
path: .spaces[6].metrics.loc.lloc
old: 6.0
new: 1.0
path: .spaces[6].metrics.loc.ploc
old: 13.0
new: 7.0
path: .spaces[6].metrics.loc.cloc
old: 0.0
new: 1.0
path: .spaces[6].metrics.loc.sloc
old: 15.0
new: 8.0
path: .spaces[6].metrics.loc.blank
old: 2.0
new: 0.0
path: .spaces[6].metrics.cognitive.sum
old: 2.0
new: 0.0
path: .spaces[6].metrics.cognitive.average
old: 2.0
new: 0.0
path: .spaces[6].metrics.halstead.N1
old: 45.0
new: 26.0
path: .spaces[6].metrics.halstead.n1
old: 14.0
new: 11.0
path: .spaces[6].metrics.halstead.effort
old: 4195.12185889503
new: 1913.293469362428
path: .spaces[6].metrics.halstead.N2
old: 31.0
new: 18.0
path: .spaces[6].metrics.halstead.bugs
old: 0.08670453212407479
new: 0.051372788298157376
path: .spaces[6].metrics.halstead.purity_ratio
old: 1.8387043527178115
new: 1.6198415625882705
path: .spaces[6].metrics.halstead.vocabulary
old: 34.0
new: 21.0
path: .spaces[6].metrics.halstead.length
old: 76.0
new: 44.0
path: .spaces[6].metrics.halstead.estimated_program_length
old: 139.7415308065537
new: 71.27302875388389
path: .spaces[6].metrics.halstead.difficulty
old: 10.85
new: 9.9
path: .spaces[6].metrics.halstead.time
old: 233.0623254941683
new: 106.294081631246
path: .spaces[6].metrics.halstead.level
old: 0.09216589861751152
new: 0.101010101010101
path: .spaces[6].metrics.halstead.n2
old: 20.0
new: 10.0
path: .spaces[6].metrics.halstead.volume
old: 386.64717593502576
new: 193.26196660226543
path: .spaces[6].metrics.cyclomatic.average
old: 3.0
new: 1.0
path: .spaces[6].metrics.cyclomatic.sum
old: 3.0
new: 1.0
path: .spaces[6].metrics.mi.mi_sei
old: 62.32502825086047
new: 108.71626250306196
path: .spaces[6].metrics.mi.mi_original
old: 95.4605212892386
new: 109.71000466079514
path: .spaces[6].metrics.mi.mi_visual_studio
old: 55.824866251016715
new: 64.15789746245329
path: .spaces[6].metrics.nexits.average
old: 3.0
new: 0.0
path: .spaces[6].metrics.nexits.sum
old: 3.0
new: 0.0
Code
TEST(ArenaAllocator, AllocateInDifferentChunks)
{
// Test default 1-byte alignment.
ArenaAllocator<4096> a;
void* x = a.Allocate(4000);
void* y = a.Allocate(4000);
EXPECT_NE(uintptr_t(x) + 4000, uintptr_t(y));
}
Minimal test - lines (234, 278)
path: .spaces[11].metrics.cyclomatic.average
old: 1.0
new: 2.0
path: .spaces[11].metrics.cyclomatic.sum
old: 1.0
new: 2.0
path: .spaces[11].metrics.nexits.sum
old: 1.0
new: 0.0
path: .spaces[11].metrics.nexits.average
old: 1.0
new: 0.0
path: .spaces[11].metrics.halstead.N1
old: 20.0
new: 92.0
path: .spaces[11].metrics.halstead.purity_ratio
old: 2.235902344426084
new: 0.7660243308071072
path: .spaces[11].metrics.halstead.bugs
old: 0.036044128904624655
new: 0.24165245105969993
path: .spaces[11].metrics.halstead.n2
old: 9.0
new: 20.0
path: .spaces[11].metrics.halstead.level
old: 0.125
new: 0.04329004329004329
path: .spaces[11].metrics.halstead.vocabulary
old: 21.0
new: 32.0
path: .spaces[11].metrics.halstead.volume
old: 140.55415752892034
new: 845.0
path: .spaces[11].metrics.halstead.difficulty
old: 8.0
new: 23.1
path: .spaces[11].metrics.halstead.estimated_program_length
old: 71.54887502163469
new: 129.45811190640111
path: .spaces[11].metrics.halstead.length
old: 32.0
new: 169.0
path: .spaces[11].metrics.halstead.N2
old: 12.0
new: 77.0
path: .spaces[11].metrics.halstead.effort
old: 1124.4332602313627
new: 19519.5
path: .spaces[11].metrics.halstead.time
old: 62.46851445729793
new: 1084.4166666666667
path: .spaces[11].metrics.loc.blank
old: 0.0
new: 9.0
path: .spaces[11].metrics.loc.ploc
old: 4.0
new: 28.0
path: .spaces[11].metrics.loc.lloc
old: 1.0
new: 19.0
path: .spaces[11].metrics.loc.cloc
old: 0.0
new: 8.0
path: .spaces[11].metrics.loc.sloc
old: 4.0
new: 45.0
path: .spaces[11].metrics.nargs.average
old: 0.0
new: 2.0
path: .spaces[11].metrics.nargs.sum
old: 0.0
new: 2.0
path: .spaces[11].metrics.cognitive.average
old: 0.0
new: 1.0
path: .spaces[11].metrics.cognitive.sum
old: 0.0
new: 1.0
path: .spaces[11].metrics.mi.mi_sei
old: 101.26809194433986
new: 61.39981061755206
path: .spaces[11].metrics.mi.mi_visual_studio
old: 71.69295227349863
new: 43.17398666869212
path: .spaces[11].metrics.mi.mi_original
old: 122.59494838768263
new: 73.82751720346353
Code
TEST(ArenaAllocator, Clear)
{
// Tests that the Clear function works as expected. The best proxy for
// checking if a clear is successful is to measure the size. If it's empty we
// expect the size to be 0.
static const size_t kArenaSize = 128;
ArenaAllocator a;
// Clearing an empty arena should work.
a.Clear();
size_t sz = a.SizeOfExcludingThis(TestSizeOf);
EXPECT_EQ(sz, size_t(0));
// Allocating should work after clearing an empty arena.
void* x = a.Allocate(10);
EXPECT_TRUE(x);
size_t prev_sz = sz;
sz = a.SizeOfExcludingThis(TestSizeOf);
EXPECT_GT(sz, prev_sz);
// Allocate enough for a few arena chunks to be necessary.
for (size_t i = 0; i < kArenaSize * 2; i++) {
x = a.Allocate(1);
EXPECT_TRUE(x);
}
prev_sz = sz;
sz = a.SizeOfExcludingThis(TestSizeOf);
EXPECT_GT(sz, prev_sz);
// Clearing should reduce the size back to zero.
a.Clear();
sz = a.SizeOfExcludingThis(TestSizeOf);
EXPECT_EQ(sz, size_t(0));
// Allocating should work after clearing an arena with allocations.
x = a.Allocate(10);
EXPECT_TRUE(x);
prev_sz = sz;
sz = a.SizeOfExcludingThis(TestSizeOf);
EXPECT_GT(sz, prev_sz);
}
Minimal test - lines (121, 147)
path: .spaces[8].metrics.cyclomatic.sum
old: 1.0
new: 2.0
path: .spaces[8].metrics.cyclomatic.average
old: 1.0
new: 2.0
path: .spaces[8].metrics.loc.lloc
old: 1.0
new: 8.0
path: .spaces[8].metrics.loc.sloc
old: 3.0
new: 27.0
path: .spaces[8].metrics.loc.blank
old: 0.0
new: 2.0
path: .spaces[8].metrics.loc.cloc
old: 0.0
new: 7.0
path: .spaces[8].metrics.loc.ploc
old: 3.0
new: 18.0
path: .spaces[8].metrics.nexits.sum
old: 1.0
new: 0.0
path: .spaces[8].metrics.nexits.average
old: 1.0
new: 0.0
path: .spaces[8].metrics.halstead.time
old: 9.417341628512643
new: 650.1663531617562
path: .spaces[8].metrics.halstead.estimated_program_length
old: 27.651484454403228
new: 133.6620089600894
path: .spaces[8].metrics.halstead.difficulty
old: 3.5
new: 20.0
path: .spaces[8].metrics.halstead.N2
old: 4.0
new: 48.0
path: .spaces[8].metrics.halstead.bugs
old: 0.01020969180116028
new: 0.1718211978376847
path: .spaces[8].metrics.halstead.length
old: 14.0
new: 116.0
path: .spaces[8].metrics.halstead.n2
old: 4.0
new: 18.0
path: .spaces[8].metrics.halstead.vocabulary
old: 11.0
new: 33.0
path: .spaces[8].metrics.halstead.n1
old: 7.0
new: 15.0
path: .spaces[8].metrics.halstead.purity_ratio
old: 1.9751060324573737
new: 1.152258697931805
path: .spaces[8].metrics.halstead.N1
old: 10.0
new: 68.0
path: .spaces[8].metrics.halstead.volume
old: 48.43204266092216
new: 585.1497178455805
path: .spaces[8].metrics.halstead.level
old: 0.2857142857142857
new: 0.05
path: .spaces[8].metrics.halstead.effort
old: 169.51214931322758
new: 11702.994356911611
path: .spaces[8].metrics.nargs.sum
old: 0.0
new: 2.0
path: .spaces[8].metrics.nargs.average
old: 0.0
new: 2.0
path: .spaces[8].metrics.mi.mi_original
old: 132.79564043134943
new: 84.01373051009881
path: .spaces[8].metrics.mi.mi_sei
old: 115.98457976937348
new: 81.18476225718226
path: .spaces[8].metrics.mi.mi_visual_studio
old: 77.6582692580991
new: 49.13083655561334
path: .spaces[8].metrics.cognitive.average
old: 0.0
new: 1.0
path: .spaces[8].metrics.cognitive.sum
old: 0.0
new: 1.0
Code
TEST(ArenaAllocator, AllocationsPerChunk)
{
// Test that expected number of allocations fit in one chunk.
// We use an alignment of 64-bytes to avoid worrying about differences in
// the header size on 32 and 64-bit platforms.
const size_t kArenaSize = 1024;
const size_t kAlignment = 64;
ArenaAllocator a;
// With an alignment of 64 bytes we expect the header to take up the first
// alignment sized slot leaving bytes leaving the rest available for
// allocation.
const size_t kAllocationsPerChunk = (kArenaSize / kAlignment) - 1;
void* x = nullptr;
void* y = a.Allocate(kAlignment);
EXPECT_TRUE(y);
for (size_t i = 1; i < kAllocationsPerChunk; i++) {
x = y;
y = a.Allocate(kAlignment);
EXPECT_EQ(uintptr_t(x) + kAlignment, uintptr_t(y));
}
// The next allocation should be in a different chunk.
x = y;
y = a.Allocate(kAlignment);
EXPECT_NE(uintptr_t(x) + kAlignment, uintptr_t(y));
}
Minimal test - lines (30, 54)
path: .spaces[2].metrics.cyclomatic.sum
old: 85.0
new: 2.0
path: .spaces[2].metrics.cyclomatic.average
old: 85.0
new: 2.0
path: .spaces[2].metrics.nexits.sum
old: 9.0
new: 0.0
path: .spaces[2].metrics.nexits.average
old: 9.0
new: 0.0
path: .spaces[2].metrics.mi.mi_original
old: 33.95759580898587
new: 85.50132539347307
path: .spaces[2].metrics.mi.mi_visual_studio
old: 19.85824316314963
new: 50.00077508390238
path: .spaces[2].metrics.mi.mi_sei
old: -10.826374892786191
new: 84.40409525161638
path: .spaces[2].metrics.cognitive.average
old: 2.0
new: 1.0
path: .spaces[2].metrics.cognitive.sum
old: 2.0
new: 1.0
path: .spaces[2].metrics.halstead.estimated_program_length
old: 761.2980076365207
new: 111.90632784293425
path: .spaces[2].metrics.halstead.level
old: 0.08800690250215702
new: 0.047619047619047616
path: .spaces[2].metrics.halstead.effort
old: 28852.541515337853
new: 11732.024103233089
path: .spaces[2].metrics.halstead.vocabulary
old: 121.0
new: 29.0
path: .spaces[2].metrics.halstead.volume
old: 2539.2228080797763
new: 558.6678144396708
path: .spaces[2].metrics.halstead.n2
old: 102.0
new: 15.0
path: .spaces[2].metrics.halstead.N1
old: 245.0
new: 70.0
path: .spaces[2].metrics.halstead.length
old: 367.0
new: 115.0
path: .spaces[2].metrics.halstead.n1
old: 19.0
new: 14.0
path: .spaces[2].metrics.halstead.purity_ratio
old: 2.074381492197604
new: 0.9730985029820368
path: .spaces[2].metrics.halstead.time
old: 1602.918973074325
new: 651.7791168462826
path: .spaces[2].metrics.halstead.N2
old: 122.0
new: 45.0
path: .spaces[2].metrics.halstead.bugs
old: 0.3135702086747998
new: 0.1721052200733052
path: .spaces[2].metrics.halstead.difficulty
old: 11.362745098039216
new: 21.0
path: .spaces[2].metrics.loc.blank
old: 9.0
new: 4.0
path: .spaces[2].metrics.loc.cloc
old: 1.0
new: 7.0
path: .spaces[2].metrics.loc.sloc
old: 114.0
new: 25.0
path: .spaces[2].metrics.loc.lloc
old: 95.0
new: 4.0
path: .spaces[2].metrics.loc.ploc
old: 104.0
new: 14.0
Code
TEST(ArenaAllocator, AllocateAlignment)
{
// Test non-default 8-byte alignment.
static const size_t kAlignment = 8;
ArenaAllocator<1024, kAlignment> a;
// Make sure aligment is correct for 1-8.
for (size_t i = 1; i <= kAlignment; i++) {
// All of these should be 8 bytes
void* x = a.Allocate(i);
void* y = a.Allocate(i);
EXPECT_EQ(uintptr_t(x) + kAlignment, uintptr_t(y));
}
// Test with slightly larger than specified alignment.
void* x = a.Allocate(kAlignment + 1);
void* y = a.Allocate(kAlignment + 1);
// Given 8-byte aligment, and a non-8-byte aligned request we expect the
// allocations to be padded.
EXPECT_NE(uintptr_t(x) + kAlignment, uintptr_t(y));
// We expect 7 bytes of padding to have been added.
EXPECT_EQ(uintptr_t(x) + kAlignment * 2, uintptr_t(y));
}
Minimal test - lines (197, 232)
path: .spaces[10].metrics.cognitive.average
old: 2.0
new: 0.0
path: .spaces[10].metrics.cognitive.sum
old: 2.0
new: 0.0
path: .spaces[10].metrics.loc.sloc
old: 20.0
new: 36.0
path: .spaces[10].metrics.loc.ploc
old: 13.0
new: 22.0
path: .spaces[10].metrics.loc.blank
old: 3.0
new: 5.0
path: .spaces[10].metrics.loc.lloc
old: 6.0
new: 15.0
path: .spaces[10].metrics.loc.cloc
old: 4.0
new: 9.0
path: .spaces[10].metrics.nexits.average
old: 2.0
new: 0.0
path: .spaces[10].metrics.nexits.sum
old: 2.0
new: 0.0
path: .spaces[10].metrics.cyclomatic.sum
old: 5.0
new: 1.0
path: .spaces[10].metrics.cyclomatic.average
old: 5.0
new: 1.0
path: .spaces[10].metrics.mi.mi_sei
old: 86.91742806536371
new: 72.74366519428558
path: .spaces[10].metrics.mi.mi_original
old: 90.229526364278
new: 78.58299958795452
path: .spaces[10].metrics.mi.mi_visual_studio
old: 52.76580489139064
new: 45.95497051927165
path: .spaces[10].metrics.halstead.purity_ratio
old: 1.8836613095048704
new: 0.7705919062322578
path: .spaces[10].metrics.halstead.vocabulary
old: 35.0
new: 29.0
path: .spaces[10].metrics.halstead.time
old: 271.5314197095242
new: 917.8726444911624
path: .spaces[10].metrics.halstead.estimated_program_length
old: 145.04192083187502
new: 112.50641830990963
path: .spaces[10].metrics.halstead.n2
old: 20.0
new: 17.0
path: .spaces[10].metrics.halstead.length
old: 77.0
new: 146.0
path: .spaces[10].metrics.halstead.volume
old: 394.9547923047624
new: 709.2652252886255
path: .spaces[10].metrics.halstead.N2
old: 33.0
new: 66.0
path: .spaces[10].metrics.halstead.n1
old: 15.0
new: 12.0
path: .spaces[10].metrics.halstead.effort
old: 4887.565554771435
new: 16521.707600840924
path: .spaces[10].metrics.halstead.difficulty
old: 12.375
new: 23.294117647058822
path: .spaces[10].metrics.halstead.N1
old: 44.0
new: 80.0
path: .spaces[10].metrics.halstead.level
old: 0.08080808080808081
new: 0.04292929292929293
path: .spaces[10].metrics.halstead.bugs
old: 0.09600056939309404
new: 0.21622971031262103
path: .spaces[10].metrics.nargs.sum
old: 0.0
new: 2.0
path: .spaces[10].metrics.nargs.average
old: 0.0
new: 2.0
Code
TEST(ArenaAllocator, SizeOf)
{
// This tests the sizeof functionality. We can't test for equality as we
// can't reliably guarantee what sizes the underlying allocator is going to
// choose, so we just test that things grow (or not) as expected.
static const size_t kArenaSize = 4096;
ArenaAllocator a;
// Excluding *this we expect an empty arena allocator to have no overhead.
size_t sz = a.SizeOfExcludingThis(TestSizeOf);
EXPECT_EQ(sz, size_t(0));
// Cause one chunk to be allocated.
(void)a.Allocate(kArenaSize / 2);
size_t prev_sz = sz;
sz = a.SizeOfExcludingThis(TestSizeOf);
EXPECT_GT(sz, prev_sz);
// Allocate within the current chunk.
(void)a.Allocate(kArenaSize / 4);
prev_sz = sz;
sz = a.SizeOfExcludingThis(TestSizeOf);
EXPECT_EQ(sz, prev_sz);
// Overflow to a new chunk.
(void)a.Allocate(kArenaSize / 2);
prev_sz = sz;
sz = a.SizeOfExcludingThis(TestSizeOf);
EXPECT_GT(sz, prev_sz);
// Allocate an oversized chunk with enough room for a header to fit in page
// size. We expect the underlying allocator to round up to page alignment.
(void)a.Allocate((kArenaSize * 2) - 64);
sz = a.SizeOfExcludingThis(TestSizeOf);
EXPECT_GT(sz, prev_sz);
}
Minimal test - lines (15, 16)
path: .spaces[0].metrics.nom.functions
old: 0.0
new: 1.0
path: .spaces[0].metrics.nom.total
old: 0.0
new: 1.0
path: .spaces[0].metrics.halstead.estimated_program_length
old: 17.509775004326936
new: 31.019550008653873
path: .spaces[0].metrics.halstead.N1
old: 5.0
new: 7.0
path: .spaces[0].metrics.halstead.level
old: 0.6666666666666666
new: 0.2857142857142857
path: .spaces[0].metrics.halstead.time
old: 3.5
new: 9.75906458529648
path: .spaces[0].metrics.halstead.N2
old: 9.0
new: 7.0
path: .spaces[0].metrics.halstead.volume
old: 42.0
new: 50.18947501009619
path: .spaces[0].metrics.halstead.n1
old: 2.0
new: 6.0
path: .spaces[0].metrics.halstead.purity_ratio
old: 1.2506982145947811
new: 2.2156821434752767
path: .spaces[0].metrics.halstead.bugs
old: 0.0052776320879040755
new: 0.010455204778755302
path: .spaces[0].metrics.halstead.effort
old: 63.0
new: 175.66316253533665
path: .spaces[0].metrics.halstead.vocabulary
old: 8.0
new: 12.0
path: .spaces[0].metrics.halstead.difficulty
old: 1.5
new: 3.5
path: .spaces[0].metrics.mi.mi_sei
old: 94.12994940155043
new: 125.19357265873246
path: .spaces[0].metrics.mi.mi_original
old: 117.64716500971318
new: 139.1788278884052
path: .spaces[0].metrics.mi.mi_visual_studio
old: 68.79951170158665
new: 81.39112742012001
path: .spaces[0].metrics.cognitive.average
old: null
new: 0.0
path: .spaces[0].metrics.loc.blank
old: 2.0
new: 0.0
path: .spaces[0].metrics.loc.ploc
old: 6.0
new: 2.0
path: .spaces[0].metrics.loc.sloc
old: 8.0
new: 2.0
path: .spaces[0].metrics.nexits.average
old: null
new: 0.0
path: .spaces[0].metrics.nargs.average
old: null
new: 2.0
path: .spaces[0].metrics.nargs.sum
old: 0.0
new: 2.0
Code
TEST(ArenaAllocator, Constructor)
{ ArenaAllocator<4096, 4> a; }
Minimal test - lines (77, 95)
path: .spaces[5].metrics.nargs.sum
old: 0.0
new: 2.0
path: .spaces[5].metrics.nargs.average
old: 0.0
new: 2.0
path: .spaces[5].metrics.halstead.purity_ratio
old: 1.807910125841804
new: 1.2509849429477655
path: .spaces[5].metrics.halstead.difficulty
old: 10.88888888888889
new: 14.147058823529411
path: .spaces[5].metrics.halstead.N1
old: 43.0
new: 57.0
path: .spaces[5].metrics.halstead.n2
old: 18.0
new: 17.0
path: .spaces[5].metrics.halstead.time
old: 214.7530864197531
new: 362.5165872383065
path: .spaces[5].metrics.halstead.level
old: 0.09183673469387754
new: 0.07068607068607069
path: .spaces[5].metrics.halstead.effort
old: 3865.555555555556
new: 6525.298570289517
path: .spaces[5].metrics.halstead.bugs
old: 0.08210192844875129
new: 0.11639804085663144
path: .spaces[5].metrics.halstead.n1
old: 14.0
new: 13.0
path: .spaces[5].metrics.halstead.volume
old: 355.0
new: 461.2477159872008
path: .spaces[5].metrics.halstead.N2
old: 28.0
new: 37.0
path: .spaces[5].metrics.halstead.estimated_program_length
old: 128.36161893476807
new: 117.59258463708996
path: .spaces[5].metrics.halstead.length
old: 71.0
new: 94.0
path: .spaces[5].metrics.halstead.vocabulary
old: 32.0
new: 30.0
path: .spaces[5].metrics.loc.ploc
old: 12.0
new: 13.0
path: .spaces[5].metrics.loc.sloc
old: 14.0
new: 19.0
path: .spaces[5].metrics.loc.cloc
old: 0.0
new: 4.0
path: .spaces[5].metrics.loc.lloc
old: 6.0
new: 4.0
path: .spaces[5].metrics.nexits.average
old: 3.0
new: 0.0
path: .spaces[5].metrics.nexits.sum
old: 3.0
new: 0.0
path: .spaces[5].metrics.mi.mi_sei
old: 64.57813914782818
new: 88.09942430504881
path: .spaces[5].metrics.mi.mi_original
old: 97.02225875496066
new: 90.71362527102696
path: .spaces[5].metrics.mi.mi_visual_studio
old: 56.73816301459688
new: 53.04890366726724
Code
TEST(ArenaAllocator, AllocateMultipleSizes)
{
// Test non-default 4-byte alignment.
ArenaAllocator<4096, 4> a;
for (int i = 1; i < 50; i++) {
void* x = a.Allocate(i);
// All the allocations should be aligned properly.
EXPECT_EQ(uintptr_t(x) % 4, uintptr_t(0));
}
// Test a large 64-byte alignment
ArenaAllocator<8192, 64> b;
for (int i = 1; i < 100; i++) {
void* x = b.Allocate(i);
// All the allocations should be aligned properly.
EXPECT_EQ(uintptr_t(x) % 64, uintptr_t(0));
}
}
Minimal test - lines (18, 28)
path: .spaces[1].metrics.halstead.n1
old: 8.0
new: 11.0
path: .spaces[1].metrics.halstead.vocabulary
old: 16.0
new: 21.0
path: .spaces[1].metrics.halstead.purity_ratio
old: 2.4
new: 1.6198415625882705
path: .spaces[1].metrics.halstead.N2
old: 10.0
new: 18.0
path: .spaces[1].metrics.halstead.N1
old: 10.0
new: 26.0
path: .spaces[1].metrics.halstead.n2
old: 8.0
new: 10.0
path: .spaces[1].metrics.halstead.volume
old: 80.0
new: 193.26196660226543
path: .spaces[1].metrics.halstead.length
old: 20.0
new: 44.0
path: .spaces[1].metrics.halstead.effort
old: 400.0
new: 1913.293469362428
path: .spaces[1].metrics.halstead.bugs
old: 0.01809611744396604
new: 0.051372788298157376
path: .spaces[1].metrics.halstead.difficulty
old: 5.0
new: 9.9
path: .spaces[1].metrics.halstead.level
old: 0.2
new: 0.101010101010101
path: .spaces[1].metrics.halstead.estimated_program_length
old: 48.0
new: 71.27302875388389
path: .spaces[1].metrics.halstead.time
old: 22.22222222222222
new: 106.294081631246
path: .spaces[1].metrics.mi.mi_visual_studio
old: 73.40672096465123
new: 61.140967378172434
path: .spaces[1].metrics.mi.mi_sei
old: 105.49597390658572
new: 111.41749572111696
path: .spaces[1].metrics.mi.mi_original
old: 125.5254928495536
new: 104.55105421667486
path: .spaces[1].metrics.nexits.average
old: 1.0
new: 0.0
path: .spaces[1].metrics.nexits.sum
old: 1.0
new: 0.0
path: .spaces[1].metrics.nargs.sum
old: 0.0
new: 2.0
path: .spaces[1].metrics.nargs.average
old: 0.0
new: 2.0
path: .spaces[1].metrics.loc.cloc
old: 0.0
new: 3.0
path: .spaces[1].metrics.loc.lloc
old: 2.0
new: 1.0
path: .spaces[1].metrics.loc.ploc
old: 4.0
new: 7.0
path: .spaces[1].metrics.loc.sloc
old: 4.0
new: 11.0
path: .spaces[1].metrics.loc.blank
old: 0.0
new: 1.0
Code
TEST(ArenaAllocator, DefaultAllocate)
{
// Test default 1-byte alignment.
ArenaAllocator<1024> a;
void* x = a.Allocate(101);
void* y = a.Allocate(101);
// Given 1-byte aligment, we expect the allocations to follow
// each other exactly.
EXPECT_EQ(uintptr_t(x) + 101, uintptr_t(y));
}
Minimal test - lines (106, 119)
path: .spaces[7].metrics.cyclomatic.sum
old: 2.0
new: 1.0
path: .spaces[7].metrics.cyclomatic.average
old: 2.0
new: 1.0
path: .spaces[7].metrics.loc.sloc
old: 12.0
new: 14.0
path: .spaces[7].metrics.loc.cloc
old: 0.0
new: 2.0
path: .spaces[7].metrics.cognitive.average
old: 1.0
new: 0.0
path: .spaces[7].metrics.cognitive.sum
old: 1.0
new: 0.0
path: .spaces[7].metrics.nargs.sum
old: 0.0
new: 2.0
path: .spaces[7].metrics.nargs.average
old: 0.0
new: 2.0
path: .spaces[7].metrics.mi.mi_visual_studio
old: 59.390035514422706
new: 57.44296644067813
path: .spaces[7].metrics.mi.mi_original
old: 101.55696072966282
new: 98.2274726135596
path: .spaces[7].metrics.mi.mi_sei
old: 71.01851133923593
new: 93.74573262612287
path: .spaces[7].metrics.nexits.average
old: 2.0
new: 0.0
path: .spaces[7].metrics.nexits.sum
old: 2.0
new: 0.0
path: .spaces[7].metrics.halstead.N2
old: 22.0
new: 30.0
path: .spaces[7].metrics.halstead.N1
old: 32.0
new: 38.0
path: .spaces[7].metrics.halstead.purity_ratio
old: 1.6875049323053346
new: 1.192254379612708
path: .spaces[7].metrics.halstead.time
old: 166.0178587844464
new: 234.97391271740597
path: .spaces[7].metrics.halstead.estimated_program_length
old: 91.12526634448808
new: 81.07329781366414
path: .spaces[7].metrics.halstead.bugs
old: 0.06915606717996642
new: 0.0871779892425027
path: .spaces[7].metrics.halstead.n1
old: 13.0
new: 11.0
path: .spaces[7].metrics.halstead.level
old: 0.08391608391608392
new: 0.07272727272727272
path: .spaces[7].metrics.halstead.length
old: 54.0
new: 68.0
path: .spaces[7].metrics.halstead.vocabulary
old: 25.0
new: 23.0
path: .spaces[7].metrics.halstead.difficulty
old: 11.916666666666666
new: 13.75
path: .spaces[7].metrics.halstead.effort
old: 2988.321458120035
new: 4229.530428913307
path: .spaces[7].metrics.halstead.volume
old: 250.76823424783512
new: 307.60221301187687
Code
TEST(ArenaAllocator, AllocateLargerThanArenaSize)
{
// Test default 1-byte alignment.
ArenaAllocator<256> a;
void* x = a.Allocate(4000);
void* y = a.Allocate(4000);
EXPECT_TRUE(x);
EXPECT_TRUE(y);
// Now try a normal allocation, it should behave as expected.
x = a.Allocate(8);
y = a.Allocate(8);
EXPECT_EQ(uintptr_t(x) + 8, uintptr_t(y));
}
Minimal test - lines (149, 193)
path: .spaces[9].metrics.mi.mi_sei
old: 67.74716944168748
new: 55.5317637965356
path: .spaces[9].metrics.mi.mi_visual_studio
old: 46.70561454438987
new: 41.36133347715981
path: .spaces[9].metrics.mi.mi_original
old: 79.86660087090667
new: 70.72788024594327
path: .spaces[9].metrics.loc.cloc
old: 4.0
new: 7.0
path: .spaces[9].metrics.loc.ploc
old: 21.0
new: 34.0
path: .spaces[9].metrics.loc.lloc
old: 10.0
new: 21.0
path: .spaces[9].metrics.loc.sloc
old: 29.0
new: 45.0
path: .spaces[9].metrics.nargs.average
old: 3.0
new: 2.0
path: .spaces[9].metrics.nargs.sum
old: 3.0
new: 2.0
path: .spaces[9].metrics.nexits.average
old: 3.0
new: 0.0
path: .spaces[9].metrics.nexits.sum
old: 3.0
new: 0.0
path: .spaces[9].metrics.halstead.difficulty
old: 14.875
new: 47.111111111111114
path: .spaces[9].metrics.halstead.N1
old: 74.0
new: 158.0
path: .spaces[9].metrics.halstead.length
old: 130.0
new: 264.0
path: .spaces[9].metrics.halstead.time
old: 603.1913978365436
new: 3515.2483987543083
path: .spaces[9].metrics.halstead.n2
old: 32.0
new: 18.0
path: .spaces[9].metrics.halstead.vocabulary
old: 49.0
new: 34.0
path: .spaces[9].metrics.halstead.N2
old: 56.0
new: 106.0
path: .spaces[9].metrics.halstead.bugs
old: 0.1634420653325189
new: 0.5292949634009615
path: .spaces[9].metrics.halstead.estimated_program_length
old: 229.48686830125575
new: 139.0586500259616
path: .spaces[9].metrics.halstead.effort
old: 10857.445161057783
new: 63274.47117757755
path: .spaces[9].metrics.halstead.level
old: 0.06722689075630252
new: 0.02122641509433962
path: .spaces[9].metrics.halstead.n1
old: 17.0
new: 16.0
path: .spaces[9].metrics.halstead.purity_ratio
old: 1.765283602317352
new: 0.5267373107044
path: .spaces[9].metrics.halstead.volume
old: 729.9122797349771
new: 1343.0901900900894
path: .spaces[9].metrics.cyclomatic.average
old: 10.0
new: 5.0
path: .spaces[9].metrics.cyclomatic.sum
old: 10.0
new: 5.0
Code
TEST(ArenaAllocator, MemoryIsValid)
{
// Make multiple allocations and actually access the memory. This is
// expected to trip up ASAN or valgrind if out of bounds memory is
// accessed.
static const size_t kArenaSize = 1024;
static const size_t kAlignment = 64;
static const char kMark = char(0xBC);
ArenaAllocator a;
// Single allocation that should fill the arena.
size_t sz = kArenaSize - kAlignment;
char* x = (char*)a.Allocate(sz);
EXPECT_EQ(uintptr_t(x) % kAlignment, uintptr_t(0));
memset(x, kMark, sz);
for (size_t i = 0; i < sz; i++) {
EXPECT_EQ(x[i], kMark);
}
// Allocation over arena size.
sz = kArenaSize * 2;
x = (char*)a.Allocate(sz);
EXPECT_EQ(uintptr_t(x) % kAlignment, uintptr_t(0));
memset(x, kMark, sz);
for (size_t i = 0; i < sz; i++) {
EXPECT_EQ(x[i], kMark);
}
// Allocation half the arena size.
sz = kArenaSize / 2;
x = (char*)a.Allocate(sz);
EXPECT_EQ(uintptr_t(x) % kAlignment, uintptr_t(0));
memset(x, kMark, sz);
for (size_t i = 0; i < sz; i++) {
EXPECT_EQ(x[i], kMark);
}
// Repeat, this should actually end up in a new chunk.
x = (char*)a.Allocate(sz);
EXPECT_EQ(uintptr_t(x) % kAlignment, uintptr_t(0));
memset(x, kMark, sz);
for (size_t i = 0; i < sz; i++) {
EXPECT_EQ(x[i], kMark);
}
}
Minimal test - lines (57, 65)
path: .spaces[3].metrics.cyclomatic.average
old: 40.0
new: 1.0
path: .spaces[3].metrics.cyclomatic.sum
old: 40.0
new: 1.0
path: .spaces[3].metrics.mi.mi_sei
old: 10.158111930749548
new: 123.1163133907484
path: .spaces[3].metrics.mi.mi_original
old: 32.30727992930949
new: 110.71141750490206
path: .spaces[3].metrics.mi.mi_visual_studio
old: 18.89314615749093
new: 64.74351900871466
path: .spaces[3].metrics.nargs.sum
old: 4.0
new: 2.0
path: .spaces[3].metrics.nargs.average
old: 4.0
new: 2.0
path: .spaces[3].metrics.nexits.sum
old: 18.0
new: 0.0
path: .spaces[3].metrics.nexits.average
old: 18.0
new: 0.0
path: .spaces[3].metrics.loc.cloc
old: 51.0
new: 3.0
path: .spaces[3].metrics.loc.ploc
old: 122.0
new: 6.0
path: .spaces[3].metrics.loc.blank
old: 28.0
new: 0.0
path: .spaces[3].metrics.loc.lloc
old: 64.0
new: 1.0
path: .spaces[3].metrics.loc.sloc
old: 201.0
new: 9.0
path: .spaces[3].metrics.cognitive.sum
old: 68.0
new: 0.0
path: .spaces[3].metrics.cognitive.average
old: 68.0
new: 0.0
path: .spaces[3].metrics.halstead.purity_ratio
old: 1.1230170560813184
new: 2.374946383148248
path: .spaces[3].metrics.halstead.bugs
old: 0.8560865657512976
new: 0.027180130408583855
path: .spaces[3].metrics.halstead.n1
old: 22.0
new: 10.0
path: .spaces[3].metrics.halstead.estimated_program_length
old: 714.2388476677185
new: 61.74860596185444
path: .spaces[3].metrics.halstead.vocabulary
old: 116.0
new: 19.0
path: .spaces[3].metrics.halstead.volume
old: 4361.675912901136
new: 110.44611534953322
path: .spaces[3].metrics.halstead.n2
old: 94.0
new: 9.0
path: .spaces[3].metrics.halstead.length
old: 636.0
new: 26.0
path: .spaces[3].metrics.halstead.N2
old: 255.0
new: 12.0
path: .spaces[3].metrics.halstead.difficulty
old: 29.840425531914892
new: 6.666666666666667
path: .spaces[3].metrics.halstead.level
old: 0.03351158645276293
new: 0.15
path: .spaces[3].metrics.halstead.time
old: 7230.792515181847
new: 40.905968647975264
path: .spaces[3].metrics.halstead.effort
old: 130154.26527327324
new: 736.3074356635548
path: .spaces[3].metrics.halstead.N1
old: 381.0
new: 14.0
Code
TEST(ArenaAllocator, AllocateZeroBytes)
{
// This would have to be a death test. Since we chose to provide an
// infallible allocator we can't just return nullptr in the 0 case as
// there's no way to differentiate that from the OOM case.
ArenaAllocator<1024> a;
void* x = a.Allocate(0);
EXPECT_FALSE(x);
}
Minimal test - lines (280, 310)
path: .spaces[12].metrics.halstead.level
old: 0.07017543859649122
new: 0.08
path: .spaces[12].metrics.halstead.volume
old: 663.2550430017876
new: 895.3467854565167
path: .spaces[12].metrics.halstead.N2
old: 57.0
new: 75.0
path: .spaces[12].metrics.halstead.n2
old: 28.0
new: 33.0
path: .spaces[12].metrics.halstead.estimated_program_length
old: 187.90890672641936
new: 204.51875374383923
path: .spaces[12].metrics.halstead.N1
old: 66.0
new: 89.0
path: .spaces[12].metrics.halstead.difficulty
old: 14.25
new: 12.5
path: .spaces[12].metrics.halstead.purity_ratio
old: 1.5277146888326778
new: 1.2470655716087755
path: .spaces[12].metrics.halstead.n1
old: 14.0
new: 11.0
path: .spaces[12].metrics.halstead.bugs
old: 0.14900780892249044
new: 0.16678088464009913
path: .spaces[12].metrics.halstead.length
old: 123.0
new: 164.0
path: .spaces[12].metrics.halstead.effort
old: 9451.384362775474
new: 11191.834818206458
path: .spaces[12].metrics.halstead.time
old: 525.0769090430819
new: 621.7686010114699
path: .spaces[12].metrics.halstead.vocabulary
old: 42.0
new: 44.0
path: .spaces[12].metrics.cyclomatic.sum
old: 2.0
new: 1.0
path: .spaces[12].metrics.cyclomatic.average
old: 2.0
new: 1.0
path: .spaces[12].metrics.nargs.average
old: 5.0
new: 2.0
path: .spaces[12].metrics.nargs.sum
old: 5.0
new: 2.0
path: .spaces[12].metrics.nexits.average
old: 2.0
new: 0.0
path: .spaces[12].metrics.nexits.sum
old: 2.0
new: 0.0
path: .spaces[12].metrics.loc.lloc
old: 10.0
new: 6.0
path: .spaces[12].metrics.loc.cloc
old: 1.0
new: 3.0
path: .spaces[12].metrics.loc.ploc
old: 18.0
new: 22.0
path: .spaces[12].metrics.loc.blank
old: 2.0
new: 6.0
path: .spaces[12].metrics.loc.sloc
old: 21.0
new: 31.0
path: .spaces[12].metrics.mi.mi_original
old: 87.4335066072916
new: 79.79390949968013
path: .spaces[12].metrics.mi.mi_visual_studio
old: 51.13070561829918
new: 46.66310497057317
path: .spaces[12].metrics.mi.mi_sei
old: 67.22563047890517
new: 62.693826898036846
path: .spaces[12].metrics.cognitive.average
old: 1.0
new: 0.0
path: .spaces[12].metrics.cognitive.sum
old: 1.0
new: 0.0
Code
TEST(ArenaAllocator, Extensions)
{
ArenaAllocator<4096, 8> a;
// Test with raw strings.
const char* const kTestCStr = "This is a test string.";
char* c_dup = mozilla::ArenaStrdup(kTestCStr, a);
EXPECT_STREQ(c_dup, kTestCStr);
const char16_t* const kTestStr = u"This is a wide test string.";
char16_t* dup = mozilla::ArenaStrdup(kTestStr, a);
EXPECT_TRUE(nsString(dup).Equals(kTestStr));
// Make sure it works with literal strings.
constexpr auto wideStr = u"A wide string."_ns;
nsLiteralString::char_type* wide = mozilla::ArenaStrdup(wideStr, a);
EXPECT_TRUE(wideStr.Equals(wide));
constexpr auto cStr = "A c-string."_ns;
nsLiteralCString::char_type* cstr = mozilla::ArenaStrdup(cStr, a);
EXPECT_TRUE(cStr.Equals(cstr));
// Make sure it works with normal strings.
nsAutoString x(u"testing wide");
nsAutoString::char_type* x_copy = mozilla::ArenaStrdup(x, a);
EXPECT_TRUE(x.Equals(x_copy));
nsAutoCString y("testing c-string");
nsAutoCString::char_type* y_copy = mozilla::ArenaStrdup(y, a);
EXPECT_TRUE(y.Equals(y_copy));
}