diff options
Diffstat (limited to 'function.cpp')
| -rw-r--r-- | function.cpp | 60 |
1 files changed, 33 insertions, 27 deletions
diff --git a/function.cpp b/function.cpp index cd9be4d5..ab5f0ea3 100644 --- a/function.cpp +++ b/function.cpp @@ -174,6 +174,7 @@ vector<Ref<BasicBlock>> Function::GetBasicBlocks() const BNBasicBlock** blocks = BNGetFunctionBasicBlockList(m_object, &count); vector<Ref<BasicBlock>> result; + result.reserve(count); for (size_t i = 0; i < count; i++) result.push_back(new BasicBlock(BNNewBasicBlockReference(blocks[i]))); @@ -379,6 +380,7 @@ vector<StackVariableReference> Function::GetStackVariablesReferencedByInstructio BNStackVariableReference* refs = BNGetStackVariablesReferencedByInstruction(m_object, arch->GetObject(), addr, &count); vector<StackVariableReference> result; + result.reserve(count); for (size_t i = 0; i < count; i++) { StackVariableReference ref; @@ -514,14 +516,9 @@ Confidence<vector<Variable>> Function::GetParameterVariables() const { BNParameterVariablesWithConfidence vars = BNGetFunctionParameterVariables(m_object); vector<Variable> varList; + varList.reserve(vars.count); for (size_t i = 0; i < vars.count; i++) - { - Variable var; - var.type = vars.vars[i].type; - var.index = vars.vars[i].index; - var.storage = vars.vars[i].storage; - varList.push_back(var); - } + varList.emplace_back(vars.vars[i].type, vars.vars[i].index, vars.vars[i].storage); Confidence<vector<Variable>> result(varList, vars.confidence); BNFreeParameterVariables(&vars); return result; @@ -606,13 +603,14 @@ void Function::SetAutoCallingConvention(const Confidence<Ref<CallingConvention>> void Function::SetAutoParameterVariables(const Confidence<vector<Variable>>& vars) { BNParameterVariablesWithConfidence varConf; - varConf.vars = new BNVariable[vars.GetValue().size()]; - varConf.count = vars.GetValue().size(); - for (size_t i = 0; i < vars.GetValue().size(); i++) + varConf.vars = new BNVariable[vars->size()]; + varConf.count = vars->size(); + size_t i = 0; + for (auto it = vars->begin(); it != vars->end(); ++it, ++i) { - varConf.vars[i].type = vars.GetValue()[i].type; - varConf.vars[i].index = vars.GetValue()[i].index; - varConf.vars[i].storage = vars.GetValue()[i].storage; + varConf.vars[i].type = it->type; + varConf.vars[i].index = it->index; + varConf.vars[i].storage = it->storage; } varConf.confidence = vars.GetConfidence(); @@ -667,11 +665,12 @@ void Function::SetAutoRegisterStackAdjustments(const map<uint32_t, Confidence<in void Function::SetAutoClobberedRegisters(const Confidence<std::set<uint32_t>>& clobbered) { BNRegisterSetWithConfidence regs; - regs.regs = new uint32_t[clobbered.GetValue().size()]; - regs.count = clobbered.GetValue().size(); + regs.regs = new uint32_t[clobbered->size()]; + regs.count = clobbered->size(); + size_t i = 0; - for (auto reg : clobbered.GetValue()) - regs.regs[i++] = reg; + for (auto it = clobbered->begin(); it != clobbered->end(); ++it, ++i) + regs.regs[i] = *it; regs.confidence = clobbered.GetConfidence(); BNSetAutoFunctionClobberedRegisters(m_object, ®s); delete[] regs.regs; @@ -718,13 +717,14 @@ void Function::SetCallingConvention(const Confidence<Ref<CallingConvention>>& co void Function::SetParameterVariables(const Confidence<vector<Variable>>& vars) { BNParameterVariablesWithConfidence varConf; - varConf.vars = new BNVariable[vars.GetValue().size()]; - varConf.count = vars.GetValue().size(); - for (size_t i = 0; i < vars.GetValue().size(); i++) + varConf.vars = new BNVariable[vars->size()]; + varConf.count = vars->size(); + size_t i = 0; + for (auto it = vars->begin(); it != vars->end(); ++it, ++i) { - varConf.vars[i].type = vars.GetValue()[i].type; - varConf.vars[i].index = vars.GetValue()[i].index; - varConf.vars[i].storage = vars.GetValue()[i].storage; + varConf.vars[i].type = it->type; + varConf.vars[i].index = it->index; + varConf.vars[i].storage = it->storage; } varConf.confidence = vars.GetConfidence(); @@ -779,11 +779,11 @@ void Function::SetRegisterStackAdjustments(const map<uint32_t, Confidence<int32_ void Function::SetClobberedRegisters(const Confidence<std::set<uint32_t>>& clobbered) { BNRegisterSetWithConfidence regs; - regs.regs = new uint32_t[clobbered.GetValue().size()]; - regs.count = clobbered.GetValue().size(); + regs.regs = new uint32_t[clobbered->size()]; + regs.count = clobbered->size(); size_t i = 0; - for (auto reg : clobbered.GetValue()) - regs.regs[i++] = reg; + for (auto it = clobbered->begin(); it != clobbered->end(); ++it, ++i) + regs.regs[i] = *it; regs.confidence = clobbered.GetConfidence(); BNSetUserFunctionClobberedRegisters(m_object, ®s); delete[] regs.regs; @@ -980,6 +980,7 @@ vector<IndirectBranchInfo> Function::GetIndirectBranches() BNIndirectBranchInfo* branches = BNGetIndirectBranches(m_object, &count); vector<IndirectBranchInfo> result; + result.reserve(count); for (size_t i = 0; i < count; i++) { IndirectBranchInfo b; @@ -1002,6 +1003,7 @@ vector<IndirectBranchInfo> Function::GetIndirectBranchesAt(Architecture* arch, u BNIndirectBranchInfo* branches = BNGetIndirectBranchesAt(m_object, arch->GetObject(), addr, &count); vector<IndirectBranchInfo> result; + result.reserve(count); for (size_t i = 0; i < count; i++) { IndirectBranchInfo b; @@ -1114,9 +1116,11 @@ vector<vector<InstructionTextToken>> Function::GetBlockAnnotations(Architecture* BNInstructionTextLine* lines = BNGetFunctionBlockAnnotations(m_object, arch->GetObject(), addr, &count); vector<vector<InstructionTextToken>> result; + result.reserve(count); for (size_t i = 0; i < count; i++) { vector<InstructionTextToken> line; + line.reserve(lines[i].count); for (size_t j = 0; j < lines[i].count; j++) { InstructionTextToken token; @@ -1328,10 +1332,12 @@ vector<DisassemblyTextLine> Function::GetTypeTokens(DisassemblySettings* setting settings ? settings->GetObject() : nullptr, &count); vector<DisassemblyTextLine> result; + result.reserve(count); for (size_t i = 0; i < count; i++) { DisassemblyTextLine line; line.addr = lines[i].addr; + line.tokens.reserve(lines[i].count); for (size_t j = 0; j < lines[i].count; j++) { InstructionTextToken token; |
