Skip to content

Commit

Permalink
Merge branch 'sasa1977-cache-scope-priorities'
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrene committed Dec 6, 2023
2 parents 48bb218 + 5aa5a58 commit e563af9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/credo/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Credo.Application do
Credo.Service.SourceFileAST,
Credo.Service.SourceFileLines,
Credo.Service.SourceFileScopes,
Credo.Service.SourceFileScopePriorities,
Credo.Service.SourceFileSource
]

Expand Down
14 changes: 13 additions & 1 deletion lib/credo/check.ex
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ defmodule Credo.Check do
warning: 16
}

alias Credo.Service.SourceFileScopePriorities
alias Credo.Check
alias Credo.Check.Params
alias Credo.Code.Scope
Expand Down Expand Up @@ -759,7 +760,18 @@ defmodule Credo.Check do
end

defp priority_for(source_file, scope) do
scope_prio_map = Priority.scope_priorities(source_file)
# Caching scope priorities, because these have to be computed only once per file. This
# significantly speeds up the execution time when a large number of issues are generated.
scope_prio_map =
case SourceFileScopePriorities.get(source_file) do
{:ok, value} ->
value

:notfound ->
result = Priority.scope_priorities(source_file)
SourceFileScopePriorities.put(source_file, result)
result
end

scope_prio_map[scope] || 0
end
Expand Down
5 changes: 5 additions & 0 deletions lib/credo/service/source_file_scope_priorities.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule Credo.Service.SourceFileScopePriorities do
@moduledoc false

use Credo.Service.ETSTableHelper
end

0 comments on commit e563af9

Please sign in to comment.