Skip to content

Commit 4c8fa39

Browse files
committed
Move implementations of key functions on Variable and SSAVariable to headers
These types are heavily used as map keys so allowing the compiler to inline these functions makes map lookups cheaper.
1 parent 623f07a commit 4c8fa39

File tree

4 files changed

+47
-121
lines changed

4 files changed

+47
-121
lines changed

binaryninjaapi.h

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10048,17 +10048,38 @@ namespace BinaryNinja {
1004810048
*/
1004910049
struct Variable : public BNVariable
1005010050
{
10051-
Variable();
10052-
Variable(BNVariableSourceType type, uint32_t index, uint64_t storage);
10053-
Variable(BNVariableSourceType type, uint64_t storage);
10054-
Variable(const BNVariable& var);
10055-
Variable(const Variable& var);
10051+
Variable() : BNVariable{RegisterVariableSourceType, 0, 0} {}
10052+
Variable(BNVariableSourceType type, uint64_t storage) : Variable(type, 0, storage) {}
10053+
Variable(BNVariableSourceType type, uint32_t index, uint64_t storage)
10054+
: BNVariable{type, index, static_cast<int64_t>(storage)}
10055+
{
10056+
}
10057+
Variable(const BNVariable& var) : BNVariable(var) {}
10058+
10059+
Variable(const Variable&) = default;
10060+
Variable& operator=(const Variable&) = default;
1005610061

10057-
Variable& operator=(const Variable& var);
10062+
Variable(Variable&&) = default;
10063+
Variable& operator=(Variable&&) = default;
10064+
10065+
bool operator==(const Variable& var) const
10066+
{
10067+
return type == var.type && index == var.index && storage == var.storage;
10068+
}
1005810069

10059-
bool operator==(const Variable& var) const;
10060-
bool operator!=(const Variable& var) const;
10061-
bool operator<(const Variable& var) const;
10070+
bool operator!=(const Variable& var) const
10071+
{
10072+
return !(*this == var);
10073+
}
10074+
10075+
bool operator<(const Variable& var) const
10076+
{
10077+
if (type != var.type)
10078+
return type < var.type;
10079+
if (storage != var.storage)
10080+
return storage < var.storage;
10081+
return index < var.index;
10082+
}
1006210083

1006310084
uint64_t ToIdentifier() const;
1006410085
static Variable FromIdentifier(uint64_t id);

function.cpp

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -29,69 +29,6 @@ using namespace BinaryNinja;
2929
using namespace std;
3030

3131

32-
Variable::Variable()
33-
{
34-
type = RegisterVariableSourceType;
35-
index = 0;
36-
storage = 0;
37-
}
38-
39-
40-
Variable::Variable(BNVariableSourceType t, uint32_t i, uint64_t s)
41-
{
42-
type = t;
43-
index = i;
44-
storage = s;
45-
}
46-
47-
48-
Variable::Variable(const BNVariable& var)
49-
{
50-
type = var.type;
51-
index = var.index;
52-
storage = var.storage;
53-
}
54-
55-
56-
Variable::Variable(const Variable& var)
57-
{
58-
type = var.type;
59-
index = var.index;
60-
storage = var.storage;
61-
}
62-
63-
64-
Variable& Variable::operator=(const Variable& var)
65-
{
66-
type = var.type;
67-
index = var.index;
68-
storage = var.storage;
69-
return *this;
70-
}
71-
72-
73-
bool Variable::operator==(const Variable& var) const
74-
{
75-
if (type != var.type)
76-
return false;
77-
if (index != var.index)
78-
return false;
79-
return storage == var.storage;
80-
}
81-
82-
83-
bool Variable::operator!=(const Variable& var) const
84-
{
85-
return !((*this) == var);
86-
}
87-
88-
89-
bool Variable::operator<(const Variable& var) const
90-
{
91-
return ToIdentifier() < var.ToIdentifier();
92-
}
93-
94-
9532
uint64_t Variable::ToIdentifier() const
9633
{
9734
return BNToVariableIdentifier(this);

mediumlevelilinstruction.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -307,47 +307,6 @@ unordered_map<BNMediumLevelILOperation, unordered_map<MediumLevelILOperandUsage,
307307
MediumLevelILInstructionBase::operationOperandIndex = GetOperandIndexForOperandUsages();
308308

309309

310-
SSAVariable::SSAVariable() : version(0) {}
311-
312-
313-
SSAVariable::SSAVariable(const Variable& v, size_t i) : var(v), version(i) {}
314-
315-
316-
SSAVariable::SSAVariable(const SSAVariable& v) : var(v.var), version(v.version) {}
317-
318-
319-
SSAVariable& SSAVariable::operator=(const SSAVariable& v)
320-
{
321-
var = v.var;
322-
version = v.version;
323-
return *this;
324-
}
325-
326-
327-
bool SSAVariable::operator==(const SSAVariable& v) const
328-
{
329-
if (var != v.var)
330-
return false;
331-
return version == v.version;
332-
}
333-
334-
335-
bool SSAVariable::operator!=(const SSAVariable& v) const
336-
{
337-
return !((*this) == v);
338-
}
339-
340-
341-
bool SSAVariable::operator<(const SSAVariable& v) const
342-
{
343-
if (var < v.var)
344-
return true;
345-
if (v.var < var)
346-
return false;
347-
return version < v.version;
348-
}
349-
350-
351310
bool MediumLevelILIntegerList::ListIterator::operator==(const ListIterator& a) const
352311
{
353312
return count == a.count;

mediumlevelilinstruction.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,25 @@ namespace BinaryNinja
6060
struct SSAVariable
6161
{
6262
Variable var;
63-
size_t version;
63+
size_t version = 0;
6464

65-
SSAVariable();
66-
SSAVariable(const Variable& v, size_t i);
67-
SSAVariable(const SSAVariable& v);
65+
// TODO: `= default` these when we can rely on C++20
66+
bool operator==(const SSAVariable& other) const
67+
{
68+
return var == other.var && version == other.version;
69+
}
6870

69-
SSAVariable& operator=(const SSAVariable& v);
70-
bool operator==(const SSAVariable& v) const;
71-
bool operator!=(const SSAVariable& v) const;
72-
bool operator<(const SSAVariable& v) const;
71+
bool operator!=(const SSAVariable& other) const
72+
{
73+
return !(*this == other);
74+
}
75+
76+
bool operator<(const SSAVariable& other) const
77+
{
78+
if (var != other.var)
79+
return var < other.var;
80+
return version < other.version;
81+
}
7382
};
7483

7584
/*!

0 commit comments

Comments
 (0)