Skip to content

Commit cee5130

Browse files
author
José Valim
committed
Reduce the number of ets lookups for reading impl
1 parent 1d58413 commit cee5130

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

lib/elixir/lib/module.ex

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,15 +1194,15 @@ defmodule Module do
11941194
arity = length(args)
11951195
pair = {name, arity}
11961196

1197-
# Docs must come first as they read the impl callback
1198-
compile_doc(table, pair, env, kind, args)
1197+
impl = compile_impl(table, name, env, kind, args)
1198+
compile_doc(table, pair, env, kind, args, impl)
11991199
compile_deprecated(table, pair)
1200-
compile_impl(table, name, env, kind, args)
1200+
12011201
:ok
12021202
end
12031203

1204-
defp compile_doc(table, pair, env, kind, args) do
1205-
{line, doc} = get_doc_info(table, env)
1204+
defp compile_doc(table, pair, env, kind, args, impl) do
1205+
{line, doc} = get_doc_info(table, env, impl)
12061206

12071207
# TODO: Store @since alongside the docs
12081208
_ = get_since_info(table)
@@ -1248,13 +1248,12 @@ defmodule Module do
12481248
[{:impl, value, _, _}] ->
12491249
impls = :ets.lookup_element(table, {:elixir, :impls}, 2)
12501250
{total, defaults} = args_count(args, 0, 0)
1251-
12521251
impl = {{name, total}, defaults, kind, line, file, value}
1253-
12541252
:ets.insert(table, {{:elixir, :impls}, [impl | impls]})
1253+
value
12551254

12561255
[] ->
1257-
:ok
1256+
false
12581257
end
12591258
end
12601259

@@ -1714,16 +1713,16 @@ defmodule Module do
17141713
value
17151714
end
17161715

1717-
defp get_doc_info(table, env) do
1716+
defp get_doc_info(table, env, impl) do
17181717
case :ets.take(table, :doc) do
17191718
[{:doc, {_, _} = pair, _, _}] ->
17201719
pair
17211720

1721+
[] when impl == false ->
1722+
{env.line, nil}
1723+
17221724
[] ->
1723-
case :ets.lookup(table, :impl) do
1724-
[{:impl, value, _, _}] when value != false -> {env.line, false}
1725-
_ -> {env.line, nil}
1726-
end
1725+
{env.line, false}
17271726
end
17281727
end
17291728

lib/elixir/test/elixir/protocol_test.exs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,9 @@ defmodule Protocol.ConsolidationTest do
386386

387387
test "consolidation keeps deprecated" do
388388
deprecated = [{{:ok, 1}, "Reason"}]
389-
390389
assert deprecated == Sample.__info__(:deprecated)
391390

392391
{:ok, {Sample, [{'ExDp', deprecated_bin}]}} = :beam_lib.chunks(@sample_binary, ['ExDp'])
393-
394392
assert {:elixir_deprecated_v1, deprecated} == :erlang.binary_to_term(deprecated_bin)
395393
end
396394

0 commit comments

Comments
 (0)