Class: Rinline::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/rinline/runner.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Returns a new instance of Runner.



10
11
12
13
14
# File 'lib/rinline/runner.rb', line 10

def initialize
  @debug = false
  @iseq_threshold = 50
  @file_cache = {}
end

Class Attribute Details

.currentObject

Returns the value of attribute current.



4
5
6
# File 'lib/rinline/runner.rb', line 4

def current
  @current
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



7
8
9
# File 'lib/rinline/runner.rb', line 7

def debug
  @debug
end

#file_cacheObject (readonly)

Returns the value of attribute file_cache.



8
9
10
# File 'lib/rinline/runner.rb', line 8

def file_cache
  @file_cache
end

#iseq_thresholdObject

Returns the value of attribute iseq_threshold.



7
8
9
# File 'lib/rinline/runner.rb', line 7

def iseq_threshold
  @iseq_threshold
end

Instance Method Details

#debug_print(*msg) ⇒ Object



53
54
55
# File 'lib/rinline/runner.rb', line 53

def debug_print(*msg)
  $stderr.puts(*msg) if debug
end

#optimize_class(klass) ⇒ Object Also known as: optimize_module



34
35
36
37
38
# File 'lib/rinline/runner.rb', line 34

def optimize_class(klass)
  debug_print "class: #{klass}"
  optimize_instance_methods(klass)
  optimize_instance_methods(klass.singleton_class)
end

#optimize_instance_method(klass, method_name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rinline/runner.rb', line 16

def optimize_instance_method(klass, method_name)
  debug_print "optimizing: #{klass}##{method_name}"
  optimized = Optimizer.optimize(klass, method_name)
  unless optimized
    debug_print "skipped: #{klass}##{method_name}"
    return
  end

  klass.class_eval "undef :#{method_name}; #{optimized}"
  debug_print "optimized: #{klass}##{method_name}"
end

#optimize_instance_methods(klass) ⇒ Object



28
29
30
31
32
# File 'lib/rinline/runner.rb', line 28

def optimize_instance_methods(klass)
  klass.instance_methods(false).each do |method|
    optimize_instance_method(klass, method)
  end
end

#optimize_namespace(mod) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/rinline/runner.rb', line 42

def optimize_namespace(mod)
  debug_print "namespace: #{mod}"
  optimize_module(mod)
  constants = mod.constants
  constants -= Struct.constants if mod < Struct
  constants.each do |child|
    child = mod.const_get(child)
    optimize_namespace(child) if child.is_a?(Module)
  end
end