Skip to content

Commit

Permalink
optimize memset() of MCInst_Init()
Browse files Browse the repository at this point in the history
  • Loading branch information
aquynh committed Jun 7, 2014
1 parent 5474d87 commit 30c0659
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
18 changes: 15 additions & 3 deletions MCInst.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@

#define MCINST_CACHE (ARR_SIZE(mcInst->Operands) - 1)

void MCInst_Init(MCInst *inst)
{
memset(inst, 0, sizeof(*inst));
void MCInst_Init(cs_struct *handle, MCInst *inst)
{
switch(handle->arch) {
default:
memset(inst, 0, sizeof(*inst));
break;
case CS_ARCH_X86:
inst->size = 0;
inst->flat_insn.x86.op_count = 0;
if (handle->detail) {
memset(inst->flat_insn.x86.prefix, 0, sizeof(inst->flat_insn.x86.prefix));
memset(inst->flat_insn.x86.operands, 0, sizeof(inst->flat_insn.x86.operands));
}
break;
}
}

void MCInst_clear(MCInst *inst)
Expand Down
2 changes: 1 addition & 1 deletion MCInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ struct MCInst {
uint8_t x86_prefix[4];
};

void MCInst_Init(MCInst *inst);
void MCInst_Init(cs_struct *handle, MCInst *inst);

void MCInst_clear(MCInst *inst);

Expand Down
2 changes: 1 addition & 1 deletion arch/ARM/ARMInstPrinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ void ARM_printInst(MCInst *MI, SStream *O, void *Info)
MCInst NewMI;
MCOperand *NewReg;

MCInst_Init(&NewMI);
MCInst_Init(MI->csh, &NewMI);
MCInst_setOpcode(&NewMI, Opcode);

if (isStore)
Expand Down
2 changes: 1 addition & 1 deletion cs.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ size_t cs_disasm_ex(csh ud, const uint8_t *buffer, size_t size, uint64_t offset,
offset_org = offset;

while (size > 0) {
MCInst_Init(&mci);
MCInst_Init(handle, &mci);
mci.csh = handle;

r = handle->disasm(ud, buffer, size, &mci, &insn_size, offset, handle->getinsn_info);
Expand Down

0 comments on commit 30c0659

Please sign in to comment.