Skip to content

Commit

Permalink
Optimize Doc::Method#compute_doc_info to avoid duplicate regex (#13324
Browse files Browse the repository at this point in the history
)
  • Loading branch information
straight-shoota authored Apr 20, 2023
1 parent 4b7eab9 commit 9bbd6c2
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/compiler/crystal/tools/doc/method.cr
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ class Crystal::Doc::Method
private def compute_doc_info : DocInfo?
def_doc = @def.doc
if def_doc
has_inherit = def_doc =~ /^\s*:inherit:\s*$/m
if has_inherit
ancestor_info = self.ancestor_doc_info
if ancestor_info
def_doc = def_doc.gsub(/^[ \t]*:inherit:[ \t]*$/m, ancestor_info.doc.not_nil!)
return DocInfo.new(def_doc, nil)
end
ancestor_doc_info = nil
# TODO: warn about `:inherit:` not finding an ancestor
inherit_def_doc = def_doc.gsub(/^[ \t]*:inherit:[ \t]*$/m) do
ancestor_doc_info ||= self.ancestor_doc_info
ancestor_doc_info.try(&.doc) || break
end

# TODO: warn about `:inherit:` not finding an ancestor
# inherit_def_doc is nil when breaking from the gsub block which means
# no ancestor doc info was found
if inherit_def_doc && !inherit_def_doc.same?(def_doc)
return DocInfo.new(inherit_def_doc, nil)
end

if @def.name.starts_with?(PSEUDO_METHOD_PREFIX)
Expand Down

0 comments on commit 9bbd6c2

Please sign in to comment.