Просмотр исходного кода

[typer] add a module_to_file cache to speed up display loading

Simon Krajewski 7 лет назад
Родитель
Сommit
f476308d1f
3 измененных файлов с 13 добавлено и 1 удалено
  1. 4 1
      src/context/common.ml
  2. 1 0
      src/context/display/displayToplevel.ml
  3. 8 0
      src/typing/typeloadParse.ml

+ 4 - 1
src/context/common.ml

@@ -147,6 +147,7 @@ type context = {
 	mutable run_command : string -> int;
 	file_lookup_cache : (string,string option) Hashtbl.t;
 	parser_cache : (string,(type_def * pos) list) Hashtbl.t;
+	module_to_file : (path,string) Hashtbl.t;
 	cached_macros : (path * string,((string * bool * t) list * t * tclass * Type.tclass_field)) Hashtbl.t;
 	mutable stored_typed_exprs : (int, texpr) PMap.t;
 	(* output *)
@@ -569,6 +570,7 @@ let create version s_version args =
 			tarray = (fun _ -> assert false);
 		};
 		file_lookup_cache = Hashtbl.create 0;
+		module_to_file = Hashtbl.create 0;
 		stored_typed_exprs = PMap.empty;
 		cached_macros = Hashtbl.create 0;
 		memory_marker = memory_marker;
@@ -586,7 +588,8 @@ let clone com =
 		main_class = None;
 		features = Hashtbl.create 0;
 		file_lookup_cache = Hashtbl.create 0;
-		parser_cache = Hashtbl.create 0 ;
+		parser_cache = Hashtbl.create 0;
+		module_to_file = Hashtbl.create 0;
 		callbacks = create_callbacks();
 		display_information = {
 			unresolved_identifiers = [];

+ 1 - 0
src/context/display/displayToplevel.ml

@@ -301,6 +301,7 @@ let collect ctx only_types with_type =
 			| Some name ->
 				name
 			in
+			Hashtbl.replace ctx.com.module_to_file (cfile.c_package,module_name) file;
 			process_decls cfile.c_package module_name cfile.c_decls
 		)
 	end;

+ 8 - 0
src/typing/typeloadParse.ml

@@ -128,6 +128,14 @@ let resolve_module_file com m remap p =
 	end;
 	file
 
+let resolve_module_file com m remap p =
+	try
+		Hashtbl.find com.module_to_file m
+	with Not_found ->
+		let file = resolve_module_file com m remap p in
+		Hashtbl.add com.module_to_file m file;
+		file
+
 (* let resolve_module_file com m remap p =
 	let timer = Timer.timer ["typing";"resolve_module_file"] in
 	Std.finally timer (resolve_module_file com m remap) p *)