Browse Source

cache loaded plugins (#9677)

Dimitri Pomier 5 years ago
parent
commit
32a5b1ccab
1 changed files with 14 additions and 6 deletions
  1. 14 6
      src/macro/eval/evalStdLib.ml

+ 14 - 6
src/macro/eval/evalStdLib.ml

@@ -664,6 +664,8 @@ module StdContext = struct
 		Hashtbl.find GlobalState.macro_lib f
 	)
 
+	let plugins = ref PMap.empty
+
 	let plugin_data = ref None
 
 	let register data = plugin_data := Some data
@@ -671,12 +673,18 @@ module StdContext = struct
 	let loadPlugin = vfun1 (fun filePath ->
 		let filePath = decode_string filePath in
 		let filePath = Dynlink.adapt_filename filePath in
-		(try Dynlink.loadfile filePath with Dynlink.Error error -> exc_string (Dynlink.error_message error));
-		match !plugin_data with
-			| None ->
-				vnull
-			| Some l ->
-				encode_obj_s l
+		if PMap.mem filePath !plugins then
+			PMap.find filePath !plugins
+		else begin
+			(try Dynlink.loadfile filePath with Dynlink.Error error -> exc_string (Dynlink.error_message error));
+			match !plugin_data with
+				| Some l ->
+					let vapi = encode_obj_s l in
+					plugins := PMap.add filePath vapi !plugins;
+					vapi
+				| None ->
+					vnull
+		end
 	)
 end