summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Rowe <mark@vector35.com>2025-10-20 23:28:36 -0700
committerMark Rowe <mark@vector35.com>2025-10-22 07:33:29 -0700
commit4c8fa3972ad50c07631418620eb9be44d629b2ae (patch)
tree449f00df976cc4a15602d6af4a196a91f54b6a69
parent623f07a2b44ac9dbc86bab2ea011ee5899664f15 (diff)
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.
-rw-r--r--binaryninjaapi.h39
-rw-r--r--function.cpp63
-rw-r--r--mediumlevelilinstruction.cpp41
-rw-r--r--mediumlevelilinstruction.h25
4 files changed, 47 insertions, 121 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index 90ee2585..9e90eeb8 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -10048,17 +10048,38 @@ namespace BinaryNinja {
*/
struct Variable : public BNVariable
{
- Variable();
- Variable(BNVariableSourceType type, uint32_t index, uint64_t storage);
- Variable(BNVariableSourceType type, uint64_t storage);
- Variable(const BNVariable& var);
- Variable(const Variable& var);
+ Variable() : BNVariable{RegisterVariableSourceType, 0, 0} {}
+ Variable(BNVariableSourceType type, uint64_t storage) : Variable(type, 0, storage) {}
+ Variable(BNVariableSourceType type, uint32_t index, uint64_t storage)
+ : BNVariable{type, index, static_cast<int64_t>(storage)}
+ {
+ }
+ Variable(const BNVariable& var) : BNVariable(var) {}
+
+ Variable(const Variable&) = default;
+ Variable& operator=(const Variable&) = default;
- Variable& operator=(const Variable& var);
+ Variable(Variable&&) = default;
+ Variable& operator=(Variable&&) = default;
+
+ bool operator==(const Variable& var) const
+ {
+ return type == var.type && index == var.index && storage == var.storage;
+ }
- bool operator==(const Variable& var) const;
- bool operator!=(const Variable& var) const;
- bool operator<(const Variable& var) const;
+ bool operator!=(const Variable& var) const
+ {
+ return !(*this == var);
+ }
+
+ bool operator<(const Variable& var) const
+ {
+ if (type != var.type)
+ return type < var.type;
+ if (storage != var.storage)
+ return storage < var.storage;
+ return index < var.index;
+ }
uint64_t ToIdentifier() const;
static Variable FromIdentifier(uint64_t id);
diff --git a/function.cpp b/function.cpp
index 1d35aa7d..df41b977 100644
--- a/function.cpp
+++ b/function.cpp
@@ -29,69 +29,6 @@ using namespace BinaryNinja;
using namespace std;
-Variable::Variable()
-{
- type = RegisterVariableSourceType;
- index = 0;
- storage = 0;
-}
-
-
-Variable::Variable(BNVariableSourceType t, uint32_t i, uint64_t s)
-{
- type = t;
- index = i;
- storage = s;
-}
-
-
-Variable::Variable(const BNVariable& var)
-{
- type = var.type;
- index = var.index;
- storage = var.storage;
-}
-
-
-Variable::Variable(const Variable& var)
-{
- type = var.type;
- index = var.index;
- storage = var.storage;
-}
-
-
-Variable& Variable::operator=(const Variable& var)
-{
- type = var.type;
- index = var.index;
- storage = var.storage;
- return *this;
-}
-
-
-bool Variable::operator==(const Variable& var) const
-{
- if (type != var.type)
- return false;
- if (index != var.index)
- return false;
- return storage == var.storage;
-}
-
-
-bool Variable::operator!=(const Variable& var) const
-{
- return !((*this) == var);
-}
-
-
-bool Variable::operator<(const Variable& var) const
-{
- return ToIdentifier() < var.ToIdentifier();
-}
-
-
uint64_t Variable::ToIdentifier() const
{
return BNToVariableIdentifier(this);
diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp
index 8a026aad..1894294b 100644
--- a/mediumlevelilinstruction.cpp
+++ b/mediumlevelilinstruction.cpp
@@ -307,47 +307,6 @@ unordered_map<BNMediumLevelILOperation, unordered_map<MediumLevelILOperandUsage,
MediumLevelILInstructionBase::operationOperandIndex = GetOperandIndexForOperandUsages();
-SSAVariable::SSAVariable() : version(0) {}
-
-
-SSAVariable::SSAVariable(const Variable& v, size_t i) : var(v), version(i) {}
-
-
-SSAVariable::SSAVariable(const SSAVariable& v) : var(v.var), version(v.version) {}
-
-
-SSAVariable& SSAVariable::operator=(const SSAVariable& v)
-{
- var = v.var;
- version = v.version;
- return *this;
-}
-
-
-bool SSAVariable::operator==(const SSAVariable& v) const
-{
- if (var != v.var)
- return false;
- return version == v.version;
-}
-
-
-bool SSAVariable::operator!=(const SSAVariable& v) const
-{
- return !((*this) == v);
-}
-
-
-bool SSAVariable::operator<(const SSAVariable& v) const
-{
- if (var < v.var)
- return true;
- if (v.var < var)
- return false;
- return version < v.version;
-}
-
-
bool MediumLevelILIntegerList::ListIterator::operator==(const ListIterator& a) const
{
return count == a.count;
diff --git a/mediumlevelilinstruction.h b/mediumlevelilinstruction.h
index a1f8e00d..077ced5b 100644
--- a/mediumlevelilinstruction.h
+++ b/mediumlevelilinstruction.h
@@ -60,16 +60,25 @@ namespace BinaryNinja
struct SSAVariable
{
Variable var;
- size_t version;
+ size_t version = 0;
- SSAVariable();
- SSAVariable(const Variable& v, size_t i);
- SSAVariable(const SSAVariable& v);
+ // TODO: `= default` these when we can rely on C++20
+ bool operator==(const SSAVariable& other) const
+ {
+ return var == other.var && version == other.version;
+ }
- SSAVariable& operator=(const SSAVariable& v);
- bool operator==(const SSAVariable& v) const;
- bool operator!=(const SSAVariable& v) const;
- bool operator<(const SSAVariable& v) const;
+ bool operator!=(const SSAVariable& other) const
+ {
+ return !(*this == other);
+ }
+
+ bool operator<(const SSAVariable& other) const
+ {
+ if (var != other.var)
+ return var < other.var;
+ return version < other.version;
+ }
};
/*!