Module: Optimize::Harness

Defined in:
lib/optimize/harness.rb

Defined Under Namespace

Classes: LoadIseqHook

Constant Summary collapse

OPT_OUT_RE =
/\A#\s*rbs-optimize\s*:\s*false\s*\z/

Class Method Summary collapse

Class Method Details

.install(passes: Pipeline.default.passes) ⇒ Object

Install a single process-wide hook that runs ‘passes` on every loaded iseq. Calling `install` a second time replaces the previous hook. Returns the installed `LoadIseqHook` so the caller can `uninstall` later.



21
22
23
24
25
26
# File 'lib/optimize/harness.rb', line 21

def install(passes: Pipeline.default.passes)
  @current&.uninstall
  @current = LoadIseqHook.new(passes: passes)
  @current.install
  @current
end

.opted_out?(source) ⇒ Boolean

Whether the source file has opted out of optimization. Scans the first 5 lines for a ‘# rbs-optimize: false` directive.

Returns:

  • (Boolean)


14
15
16
# File 'lib/optimize/harness.rb', line 14

def opted_out?(source)
  source.each_line.first(5).any? { |line| OPT_OUT_RE.match?(line.chomp) }
end

.uninstallObject

Uninstall the currently-installed hook, if any. No-op otherwise.



29
30
31
32
# File 'lib/optimize/harness.rb', line 29

def uninstall
  @current&.uninstall
  @current = nil
end