aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src/code.erl
diff options
context:
space:
mode:
authorMichał Muskała <[email protected]>2018-03-07 10:56:23 +0100
committerMichał Muskała <[email protected]>2018-03-07 11:34:25 +0100
commit3e0cecc541fc9cd85b4c5878e58a7ec4a3142368 (patch)
tree5df7afc7a1a10f670d81a2f30a344f4d5190e809 /lib/kernel/src/code.erl
parent64dc3c39cbd19d6b75e5b74cfdfdd57419d4c455 (diff)
downloadotp-3e0cecc541fc9cd85b4c5878e58a7ec4a3142368.tar.gz
otp-3e0cecc541fc9cd85b4c5878e58a7ec4a3142368.tar.bz2
otp-3e0cecc541fc9cd85b4c5878e58a7ec4a3142368.zip
Short-circuit code:ensure_loaded for already-loaded modules
This checks if the module is already loaded using erlang:module_loaded before calling the code server. This should improve performance of the call significantly since the case where module is already loaded is the common one. The change shouldn't cause any problems. It's worth noting that code:ensure_modules_loaded already does a similar check.
Diffstat (limited to 'lib/kernel/src/code.erl')
-rw-r--r--lib/kernel/src/code.erl7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/kernel/src/code.erl b/lib/kernel/src/code.erl
index 9969021a6c..f143a49d2f 100644
--- a/lib/kernel/src/code.erl
+++ b/lib/kernel/src/code.erl
@@ -149,8 +149,11 @@ load_file(Mod) when is_atom(Mod) ->
-spec ensure_loaded(Module) -> {module, Module} | {error, What} when
Module :: module(),
What :: embedded | badfile | nofile | on_load_failure.
-ensure_loaded(Mod) when is_atom(Mod) ->
- call({ensure_loaded,Mod}).
+ensure_loaded(Mod) when is_atom(Mod) ->
+ case erlang:module_loaded(Mod) of
+ true -> {module, Mod};
+ false -> call({ensure_loaded,Mod})
+ end.
%% XXX File as an atom is allowed only for backwards compatibility.
-spec load_abs(Filename) -> load_ret() when