diff options
Diffstat (limited to 'vendor/github.com/chenzhuoyu/iasm/x86_64/pools.go')
-rw-r--r-- | vendor/github.com/chenzhuoyu/iasm/x86_64/pools.go | 117 |
1 files changed, 19 insertions, 98 deletions
diff --git a/vendor/github.com/chenzhuoyu/iasm/x86_64/pools.go b/vendor/github.com/chenzhuoyu/iasm/x86_64/pools.go index 06f85ac26..8e6cbbd8a 100644 --- a/vendor/github.com/chenzhuoyu/iasm/x86_64/pools.go +++ b/vendor/github.com/chenzhuoyu/iasm/x86_64/pools.go @@ -1,117 +1,38 @@ package x86_64 -import ( - `sync` -) - -var ( - labelPool sync.Pool - programPool sync.Pool - instructionPool sync.Pool - memoryOperandPool sync.Pool -) - -func freeLabel(v *Label) { - labelPool.Put(v) -} - -func clearLabel(p *Label) *Label { - *p = Label{} - return p -} - // CreateLabel creates a new Label, it may allocate a new one or grab one from a pool. func CreateLabel(name string) *Label { - var p *Label - var v interface{} + p := new(Label) - /* attempt to grab from the pool */ - if v = labelPool.Get(); v == nil { - p = new(Label) - } else { - p = clearLabel(v.(*Label)) - } - - /* initialize the label */ - p.refs = 1 - p.Name = name - return p + /* initialize the label */ + p.refs = 1 + p.Name = name + return p } func newProgram(arch *Arch) *Program { - var p *Program - var v interface{} - - /* attempt to grab from the pool */ - if v = programPool.Get(); v == nil { - p = new(Program) - } else { - p = clearProgram(v.(*Program)) - } - - /* initialize the program */ - p.arch = arch - return p -} - -func freeProgram(p *Program) { - programPool.Put(p) -} + p := new(Program) -func clearProgram(p *Program) *Program { - *p = Program{} - return p + /* initialize the program */ + p.arch = arch + return p } func newInstruction(name string, argc int, argv Operands) *Instruction { - var v interface{} - var p *Instruction - - /* attempt to grab from the pool */ - if v = instructionPool.Get(); v == nil { - p = new(Instruction) - } else { - p = clearInstruction(v.(*Instruction)) - } - - /* initialize the instruction */ - p.name = name - p.argc = argc - p.argv = argv - return p -} - -func freeInstruction(v *Instruction) { - instructionPool.Put(v) -} + p := new(Instruction) -func clearInstruction(p *Instruction) *Instruction { - *p = Instruction { prefix: p.prefix[:0] } - return p -} - -func freeMemoryOperand(m *MemoryOperand) { - memoryOperandPool.Put(m) -} - -func clearMemoryOperand(m *MemoryOperand) *MemoryOperand { - *m = MemoryOperand{} - return m + /* initialize the instruction */ + p.name = name + p.argc = argc + p.argv = argv + return p } // CreateMemoryOperand creates a new MemoryOperand, it may allocate a new one or grab one from a pool. func CreateMemoryOperand() *MemoryOperand { - var v interface{} - var p *MemoryOperand - - /* attempt to grab from the pool */ - if v = memoryOperandPool.Get(); v == nil { - p = new(MemoryOperand) - } else { - p = clearMemoryOperand(v.(*MemoryOperand)) - } + p := new(MemoryOperand) - /* initialize the memory operand */ - p.refs = 1 - return p + /* initialize the memory operand */ + p.refs = 1 + return p } |