-
Notifications
You must be signed in to change notification settings - Fork 0
/
AllocationPath.cpp
148 lines (85 loc) · 1.93 KB
/
AllocationPath.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// AllocationPath.cpp
// Implements the AllocationPath class representing a path in the Allocation tree
#include "Globals.h"
#include <cstddef> // for size_t
#include "AllocationPath.h"
AllocationPath::AllocationPath()
{
}
AllocationPath::AllocationPath(CodeLocation * a_CodeLocation)
{
m_Segments.push_back(a_CodeLocation);
}
AllocationPath::AllocationPath(AllocationPath && a_Src):
m_Segments(std::move(a_Src.m_Segments))
{
}
AllocationPath::AllocationPath(const AllocationPath & a_Src):
m_Segments(a_Src.m_Segments)
{
}
bool AllocationPath::operator ==(const AllocationPath & a_Other)
{
auto numSegments = m_Segments.size();
if (numSegments != a_Other.m_Segments.size())
{
return false;
}
for (size_t i = 0; i < numSegments; ++i)
{
if (m_Segments[i] != a_Other.m_Segments[i])
{
return false;
}
}
return true;
}
AllocationPath & AllocationPath::operator =(const AllocationPath & a_Src)
{
if (this == &a_Src)
{
return *this;
}
m_Segments = a_Src.m_Segments;
return *this;
}
AllocationPath AllocationPath::makeChild(CodeLocation * a_ChildCodeLocation) const
{
AllocationPath res(*this);
res.m_Segments.push_back(a_ChildCodeLocation);
return res;
}
AllocationPath AllocationPath::makeParent() const
{
AllocationPath res(*this);
if (!res.m_Segments.empty())
{
res.m_Segments.pop_back();
}
return res;
}
CodeLocation * AllocationPath::getLeafSegment() const
{
if (m_Segments.empty())
{
return nullptr;
}
return m_Segments.back();
}
bool AllocationPath::isChildPathOf(const AllocationPath & a_Parent)
{
// If it has less segments than the parent, it's definitely not a child:
if (m_Segments.size() <= a_Parent.m_Segments.size())
{
return false;
}
// Check all parent's segments if they are the same as ours:
for (size_t i = 0; i < a_Parent.m_Segments.size(); ++i)
{
if (m_Segments[i] != a_Parent.m_Segments[i])
{
return false;
}
}
return true;
}