mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Replace map.flatten with flat_map in actionpack
This commit is contained in:
parent
ffcc6172b4
commit
817fe31196
7 changed files with 18 additions and 18 deletions
|
@ -27,7 +27,7 @@ module ActionDispatch
|
|||
marked[s] = true # mark s
|
||||
|
||||
s.group_by { |state| symbol(state) }.each do |sym, ps|
|
||||
u = ps.map { |l| followpos(l) }.flatten
|
||||
u = ps.flat_map { |l| followpos(l) }
|
||||
next if u.empty?
|
||||
|
||||
if u.uniq == [DUMMY]
|
||||
|
@ -90,7 +90,7 @@ module ActionDispatch
|
|||
firstpos(node.left)
|
||||
end
|
||||
when Nodes::Or
|
||||
node.children.map { |c| firstpos(c) }.flatten.uniq
|
||||
node.children.flat_map { |c| firstpos(c) }.uniq
|
||||
when Nodes::Unary
|
||||
firstpos(node.left)
|
||||
when Nodes::Terminal
|
||||
|
@ -105,7 +105,7 @@ module ActionDispatch
|
|||
when Nodes::Star
|
||||
firstpos(node.left)
|
||||
when Nodes::Or
|
||||
node.children.map { |c| lastpos(c) }.flatten.uniq
|
||||
node.children.flat_map { |c| lastpos(c) }.uniq
|
||||
when Nodes::Cat
|
||||
if nullable?(node.right)
|
||||
lastpos(node.left) | lastpos(node.right)
|
||||
|
|
|
@ -31,7 +31,7 @@ module ActionDispatch
|
|||
|
||||
return if acceptance_states.empty?
|
||||
|
||||
memos = acceptance_states.map { |x| tt.memo(x) }.flatten.compact
|
||||
memos = acceptance_states.flat_map { |x| tt.memo(x) }.compact
|
||||
|
||||
MatchData.new(memos)
|
||||
end
|
||||
|
|
|
@ -114,8 +114,8 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def states
|
||||
ss = @string_states.keys + @string_states.values.map(&:values).flatten
|
||||
rs = @regexp_states.keys + @regexp_states.values.map(&:values).flatten
|
||||
ss = @string_states.keys + @string_states.values.flat_map(&:values)
|
||||
rs = @regexp_states.keys + @regexp_states.values.flat_map(&:values)
|
||||
(ss + rs).uniq
|
||||
end
|
||||
|
||||
|
@ -143,11 +143,11 @@ module ActionDispatch
|
|||
def move_regexp(t, a)
|
||||
return [] if t.empty?
|
||||
|
||||
t.map { |s|
|
||||
t.flat_map { |s|
|
||||
if states = @regexp_states[s]
|
||||
states.map { |re, v| re === a ? v : nil }
|
||||
end
|
||||
}.flatten.compact.uniq
|
||||
}.compact.uniq
|
||||
end
|
||||
|
||||
def move_string(t, a)
|
||||
|
|
|
@ -16,9 +16,9 @@ module ActionDispatch
|
|||
# end
|
||||
# " #{n.object_id} [label=\"#{label}\", shape=box];"
|
||||
#}
|
||||
#memo_edges = memos.map { |k, memos|
|
||||
#memo_edges = memos.flat_map { |k, memos|
|
||||
# (memos || []).map { |v| " #{k} -> #{v.object_id};" }
|
||||
#}.flatten.uniq
|
||||
#}.uniq
|
||||
|
||||
<<-eodot
|
||||
digraph nfa {
|
||||
|
|
|
@ -34,7 +34,7 @@ module ActionDispatch
|
|||
|
||||
return if acceptance_states.empty?
|
||||
|
||||
memos = acceptance_states.map { |x| tt.memo(x) }.flatten.compact
|
||||
memos = acceptance_states.flat_map { |x| tt.memo(x) }.compact
|
||||
|
||||
MatchData.new(memos)
|
||||
end
|
||||
|
|
|
@ -42,7 +42,7 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def states
|
||||
(@table.keys + @table.values.map(&:keys).flatten).uniq
|
||||
(@table.keys + @table.values.flat_map(&:keys)).uniq
|
||||
end
|
||||
|
||||
# Returns a generalized transition graph with reduced states. The states
|
||||
|
@ -93,7 +93,7 @@ module ActionDispatch
|
|||
# Returns set of NFA states to which there is a transition on ast symbol
|
||||
# +a+ from some state +s+ in +t+.
|
||||
def following_states(t, a)
|
||||
Array(t).map { |s| inverted[s][a] }.flatten.uniq
|
||||
Array(t).flat_map { |s| inverted[s][a] }.uniq
|
||||
end
|
||||
|
||||
# Returns set of NFA states to which there is a transition on ast symbol
|
||||
|
@ -107,7 +107,7 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def alphabet
|
||||
inverted.values.map(&:keys).flatten.compact.uniq.sort_by { |x| x.to_s }
|
||||
inverted.values.flat_map(&:keys).compact.uniq.sort_by { |x| x.to_s }
|
||||
end
|
||||
|
||||
# Returns a set of NFA states reachable from some NFA state +s+ in set
|
||||
|
@ -131,9 +131,9 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def transitions
|
||||
@table.map { |to, hash|
|
||||
@table.flat_map { |to, hash|
|
||||
hash.map { |from, sym| [from, sym, to] }
|
||||
}.flatten(1)
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -53,9 +53,9 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def optional_names
|
||||
@optional_names ||= spec.grep(Nodes::Group).map { |group|
|
||||
@optional_names ||= spec.grep(Nodes::Group).flat_map { |group|
|
||||
group.grep(Nodes::Symbol)
|
||||
}.flatten.map { |n| n.name }.uniq
|
||||
}.map { |n| n.name }.uniq
|
||||
end
|
||||
|
||||
class RegexpOffsets < Journey::Visitors::Visitor # :nodoc:
|
||||
|
|
Loading…
Reference in a new issue