Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Doc::Method#compute_doc_info to avoid duplicate regex #13324

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
oprypin marked this conversation as resolved.
Show resolved Hide resolved
return DocInfo.new(inherit_def_doc, nil)
end

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