Skip to content

Commit

Permalink
It turns out dig is slower
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Jan 13, 2023
1 parent f96168f commit b692fc1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/yard-sorbet/handlers/enums_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def process

sig { params(node: YARD::Parser::Ruby::AstNode).returns(T::Boolean) }
def const_assign_node?(node)
node.type == :assign && node.dig(0, 0).type == :const
node.type == :assign && node[0][0].type == :const
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/yard-sorbet/handlers/sig_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def parse_sig(docstring, include_params: true)
sig { params(node: YARD::Parser::Ruby::AstNode, docstring: YARD::Docstring).void }
def parse_params(node, docstring)
sibling = NodeUtils.sibling_node(node)
sibling.dig(0, 0).each do |param|
param_name = param.dig(0, 0)
sibling[0][0].each do |param|
param_name = param[0][0]
types = SigToYARD.convert(param.last)
TagUtils.upsert_tag(docstring, 'param', types, param_name)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/yard-sorbet/handlers/struct_prop_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class StructPropHandler < YARD::Handlers::Ruby::Base

sig { void }
def process
name = params.dig(0, -1, -1).source
name = params[0][-1][-1].source
prop = make_prop(name)
update_state(prop)
object = YARD::CodeObjects::MethodObject.new(namespace, name, scope)
Expand Down
2 changes: 1 addition & 1 deletion lib/yard-sorbet/sig_to_yard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def self.convert(node)
# Order matters here, putting `nil` last results in a more concise return syntax in the UI (superscripted `?`):
# https://github.com/lsegal/yard/blob/cfa62ae/lib/yard/templates/helpers/html_helper.rb#L499-L500
when :nilable then convert_node(node.last) + REF_TYPES.fetch('NilClass')
when :any then node.dig(-1, 0).children.flat_map { convert_node(_1) }
when :any then node[-1][0].children.flat_map { convert_node(_1) }
else [node.source]
end
end
Expand Down

0 comments on commit b692fc1

Please sign in to comment.