Class: Senko::Compiler::Optimizer

Inherits:
Object
  • Object
show all
Defined in:
lib/senko/compiler/optimizer.rb

Instance Method Summary collapse

Instance Method Details

#optimize(instructions, seen = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/senko/compiler/optimizer.rb', line 6

def optimize(instructions, seen = {})
  return instructions if seen[instructions.object_id]

  seen[instructions.object_id] = true
  begin
    instructions.flat_map do |instruction|
      optimized = optimize_instruction(instruction, seen)
      next [] if removable?(optimized)

      inlineable?(optimized) ? optimized.payload[:schemas].first : [optimized]
    end
  ensure
    seen.delete(instructions.object_id)
  end
end