tracia 0.2.8 → 0.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/tracia/version.rb +1 -1
- data/lib/tracia.rb +24 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac587bcc0c01258f1220731adda063b6c83a7f66e87fe51da334286e7f629c7a
|
4
|
+
data.tar.gz: 972cfa5242cb2570aa6e9614fc30fa43937cf8c23390af260c0685b57573d094
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7631de3f1aaa6cae27892e120ba4eadb9318c04f4461c8697141278642d4fd18253fc8b11abb26408a306d683c0e71f8c356f03dd8c862273fdbaf4a2c6ac36
|
7
|
+
data.tar.gz: 6410a901a160249b4dab2eebe147f7a517e2ffc5da81a99d097e12d031a59e631a3b5c4ec44dfbb6566cc34d416768725cf1dd7aa09db7713e7c72719f1a7e67
|
data/lib/tracia/version.rb
CHANGED
data/lib/tracia.rb
CHANGED
@@ -90,13 +90,33 @@ class Tracia
|
|
90
90
|
|
91
91
|
root = @stack[0]
|
92
92
|
if root
|
93
|
-
|
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
|
-
|
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.
|
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-
|
11
|
+
date: 2022-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|