tracia 0.2.8 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tracia/version.rb +1 -1
  3. data/lib/tracia.rb +24 -2
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fc2d81fead9f93a65e43c6f12eab0c2c780944336bcc46a3b4b1954db607b85c
4
- data.tar.gz: 07f39b8b528e0eaf17e68e7fb25ccc3643deb83c47cc310962faab616539ff62
3
+ metadata.gz: ac587bcc0c01258f1220731adda063b6c83a7f66e87fe51da334286e7f629c7a
4
+ data.tar.gz: 972cfa5242cb2570aa6e9614fc30fa43937cf8c23390af260c0685b57573d094
5
5
  SHA512:
6
- metadata.gz: 03ab7c66bd930c473c70236ac5da77eded3bd28747d68f30d4b132b2bb2e14f2ce834d6270f20cb9f7cc3cb0c6402779ee22dc86f834a0b30797a8ee0d227e54
7
- data.tar.gz: 1fa5ac6f5a4cf003b850407d2b67d0f22f331550e014d8a5f51b8ee07b987c0d665eaa6c9b81c2090c11060df16aa63aee2e57b2b771d49145bb3bb2ba05fa0a
6
+ metadata.gz: d7631de3f1aaa6cae27892e120ba4eadb9318c04f4461c8697141278642d4fd18253fc8b11abb26408a306d683c0e71f8c356f03dd8c862273fdbaf4a2c6ac36
7
+ data.tar.gz: 6410a901a160249b4dab2eebe147f7a517e2ffc5da81a99d097e12d031a59e631a3b5c4ec44dfbb6566cc34d416768725cf1dd7aa09db7713e7c72719f1a7e67
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Tracia
4
- VERSION = "0.2.8"
4
+ VERSION = "0.2.9"
5
5
  end
data/lib/tracia.rb CHANGED
@@ -90,13 +90,33 @@ class Tracia
90
90
 
91
91
  root = @stack[0]
92
92
  if root
93
- non_tail_recursion!([root]) if @non_tail_recursion
93
+ eliminate_tail_recursion!([root]) if @non_tail_recursion
94
94
  @logger.call(root)
95
95
  end
96
96
  end
97
97
 
98
98
  private
99
99
 
100
+ def eliminate_tail_recursion!(stack)
101
+ @specific_recursion =
102
+ case @non_tail_recursion
103
+ when true
104
+ -> (_) { true }
105
+ else
106
+ target_recursions = Array === @non_tail_recursion ? @non_tail_recursion : [@non_tail_recursion]
107
+ target_recursions.map!{ |h| Frame.new(h[:klass], h[:call_sym], h[:method_name], nil, nil) }
108
+ -> (current) do
109
+ target_recursions.any? do |tr|
110
+ current.klass == tr.klass &&
111
+ current.call_sym == tr.call_sym &&
112
+ current.method_name == tr.method_name
113
+ end
114
+ end
115
+ end
116
+
117
+ non_tail_recursion!(stack)
118
+ end
119
+
100
120
  def non_tail_recursion!(stack)
101
121
  current_frame = stack.last
102
122
  last_idx = current_frame.children.count - 1
@@ -105,7 +125,9 @@ class Tracia
105
125
  next unless Frame === child
106
126
  next non_tail_recursion!([child]) if last_idx != idx
107
127
 
108
- recursion_idx = stack.index{ |frame| frame.same_klass_and_method?(child) }
128
+ # pp (stack + [child]).map{|f| "#{f.send(:class_and_method)}:#{f.object_id}" }
129
+
130
+ recursion_idx = @specific_recursion[child] && stack.rindex{ |frame| frame.same_klass_and_method?(child) }
109
131
  if recursion_idx
110
132
  parent = stack[recursion_idx - 1]
111
133
  parent.children << child
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tracia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-31 00:00:00.000000000 Z
11
+ date: 2022-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry