Skip to content
This repository was archived by the owner on Apr 10, 2021. It is now read-only.

Commit 8ff4536

Browse files
disassembly performance improvements
1 parent bb234ca commit 8ff4536

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

byond-extools/src/core/various_testing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void init_testing()
6464
{
6565
Core::enable_profiling();
6666
debugger_initialize();
67-
bool find_unknowns = false;
67+
bool find_unknowns = true;
6868
if (find_unknowns)
6969
{
7070
std::ofstream log("unknown_opcodes.txt");

byond-extools/src/dmdism/callbacks.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <map>
4+
#include <typeindex>
45

56
#include "opcodes.h"
67

@@ -16,6 +17,10 @@
1617

1718
#define ADD_CALLBACK(op) { op, []() -> Instruction* { return new Instr_##op(op); } },
1819

20+
const std::map<Bytecode, std::type_index> type_callbacks = {
21+
22+
};
23+
1924
const std::map<Bytecode, std::function<Instruction*()>> callbacks = {
2025
ADD_CALLBACK(END)
2126
ADD_CALLBACK(NEW)

byond-extools/src/dmdism/disassembler.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ Disassembler::Disassembler(std::uint32_t* bc, unsigned int bc_len, std::vector<C
2424
Disassembly Disassembler::disassemble()
2525
{
2626
std::vector<Instruction> instrs;
27+
instrs.reserve(512);
2728
while (context_->more()) {
2829
instrs.push_back(disassemble_next());
2930
}
3031

31-
return Disassembly(instrs);
32+
return Disassembly(std::move(instrs));
3233
}
3334

3435
Instruction Disassembler::disassemble_next()
@@ -37,9 +38,10 @@ Instruction Disassembler::disassemble_next()
3738

3839
auto root = context_->eat();
3940

40-
if (callbacks.find(static_cast<Bytecode>(root)) != callbacks.end())
41+
auto cb = callbacks.find(static_cast<Bytecode>(root));
42+
if (cb != callbacks.end())
4143
{
42-
instr = callbacks.at(static_cast<Bytecode>(root))();
44+
instr = cb->second();
4345
}
4446
else
4547
{

byond-extools/src/dmdism/disassembly.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
class Disassembly
88
{
99
public:
10-
Disassembly(std::vector<Instruction> i) : instructions(i) {}
10+
Disassembly(std::vector<Instruction>&& i) : instructions(std::move(i)) {}
1111
//~Disassembly() { for (auto i : instructions) delete& i; } //heap corruption woo
1212
std::vector<Instruction> instructions;
1313
Core::Proc proc;

byond-extools/src/dmdism/instruction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Instruction
3333

3434
Opcode& opcode() { return opcode_; }
3535

36-
std::string comment() const { return comment_; }
36+
std::string comment() { return comment_; }
3737
void set_comment(std::string comment) { comment_ = comment; }
3838
void add_comment(std::string comment) { comment_ += comment; }
3939

0 commit comments

Comments
 (0)