From 9a2fee1c0ebe0327745a35f16f2a7138a755999d Mon Sep 17 00:00:00 2001 From: Pierre Curto Date: Tue, 18 Jan 2022 08:12:13 +0100 Subject: [PATCH] op, internal/ops: cleanups Remove unnecessary fill when starting a recording in op.Record. Have the exact number of possible stack kinds in ops.Ops. Signed-off-by: Pierre Curto --- internal/ops/ops.go | 10 ++++------ op/op.go | 10 +++------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/internal/ops/ops.go b/internal/ops/ops.go index ce076947..b3201009 100644 --- a/internal/ops/ops.go +++ b/internal/ops/ops.go @@ -26,7 +26,7 @@ type Ops struct { multipOp bool macroStack stack - stacks [5]stack + stacks [_StackKind]stack } type OpType byte @@ -80,7 +80,7 @@ type StackID struct { prev int } -// StateOp represents a saved operation snapshop to be restored +// StateOp represents a saved operation snapshot to be restored // later. type StateOp struct { id int @@ -108,7 +108,7 @@ const ( ClipStack StackKind = iota TransStack PassStack - MetaStack + _StackKind ) const ( @@ -180,9 +180,7 @@ func (op *ClipOp) Decode(data []byte) { func Reset(o *Ops) { o.macroStack = stack{} - for i := range o.stacks { - o.stacks[i] = stack{} - } + o.stacks = [_StackKind]stack{} // Leave references to the GC. for i := range o.refs { o.refs[i] = nil diff --git a/op/op.go b/op/op.go index f0b2620c..5d595a76 100644 --- a/op/op.go +++ b/op/op.go @@ -153,8 +153,8 @@ func Record(o *Ops) MacroOp { pc: ops.PCFor(&o.Internal), } // Reserve room for a macro definition. Updated in Stop. - ops.Write(m.ops, ops.TypeMacroLen) - m.fill() + data := ops.Write(m.ops, ops.TypeMacroLen) + data[0] = byte(ops.TypeMacro) return m } @@ -162,17 +162,13 @@ func Record(o *Ops) MacroOp { // operation for replaying it. func (m MacroOp) Stop() CallOp { ops.PopMacro(m.ops, m.id) - m.fill() + ops.FillMacro(m.ops, m.pc) return CallOp{ ops: m.ops, pc: m.pc, } } -func (m MacroOp) fill() { - ops.FillMacro(m.ops, m.pc) -} - // Add the recorded list of operations. Add // panics if the Ops containing the recording // has been reset.