From 30c065998bba8abdf1ac8d649a6714ab5dc0cf76 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Sat, 7 Jun 2014 13:30:59 +0800 Subject: [PATCH] optimize memset() of MCInst_Init() --- MCInst.c | 18 +++++++++++++++--- MCInst.h | 2 +- arch/ARM/ARMInstPrinter.c | 2 +- cs.c | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/MCInst.c b/MCInst.c index 3a70af70c9..865f4aac7f 100644 --- a/MCInst.c +++ b/MCInst.c @@ -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) diff --git a/MCInst.h b/MCInst.h index bd9b760f4b..4222df0c2d 100644 --- a/MCInst.h +++ b/MCInst.h @@ -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); diff --git a/arch/ARM/ARMInstPrinter.c b/arch/ARM/ARMInstPrinter.c index d70bb1bb06..cfd9f4ae9a 100644 --- a/arch/ARM/ARMInstPrinter.c +++ b/arch/ARM/ARMInstPrinter.c @@ -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) diff --git a/cs.c b/cs.c index 3a388e27ce..aa3a350dbb 100644 --- a/cs.c +++ b/cs.c @@ -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);