Browse Source

[display] potentially make "parser cache" timer more accurate

Jens Fischer 6 years ago
parent
commit
36f5bc8b50
1 changed files with 23 additions and 24 deletions
  1. 23 24
      src/compiler/server.ml

+ 23 - 24
src/compiler/server.ml

@@ -124,30 +124,29 @@ let rec wait_loop process_params verbose accept =
 			let sign = Define.get_signature com2.defines in
 			let sign = Define.get_signature com2.defines in
 			let ftime = file_time ffile in
 			let ftime = file_time ffile in
 			let fkey = (ffile,sign) in
 			let fkey = (ffile,sign) in
-			let t = Timer.timer ["server";"parser cache"] in
-			let data = try
-				let cfile = CompilationServer.find_file cs fkey in
-				if cfile.c_time <> ftime then raise Not_found;
-				cfile.c_package,cfile.c_decls
-			with Not_found ->
-				has_parse_error := false;
-				let data = TypeloadParse.parse_file com2 file p in
-				let info,is_unusual = if !has_parse_error then "not cached, has parse error",true
-					else if is_display_file then "not cached, is display file",true
-					else begin try
-						(* We assume that when not in display mode it's okay to cache stuff that has #if display
-						   checks. The reasoning is that non-display mode has more information than display mode. *)
-						if not com2.display.dms_display then raise Not_found;
-						let ident = Hashtbl.find Parser.special_identifier_files ffile in
-						Printf.sprintf "not cached, using \"%s\" define" ident,true
-					with Not_found ->
-						CompilationServer.cache_file cs fkey ftime data;
-						"cached",false
-				end in
-				if is_unusual then ServerMessage.parsed com2 "" (ffile,info);
-				data
-			in
-			t();
+			let data = Std.finally (Timer.timer ["server";"parser cache"]) (fun () ->
+				try
+					let cfile = CompilationServer.find_file cs fkey in
+					if cfile.c_time <> ftime then raise Not_found;
+					cfile.c_package,cfile.c_decls
+				with Not_found ->
+					has_parse_error := false;
+					let data = TypeloadParse.parse_file com2 file p in
+					let info,is_unusual = if !has_parse_error then "not cached, has parse error",true
+						else if is_display_file then "not cached, is display file",true
+						else begin try
+							(* We assume that when not in display mode it's okay to cache stuff that has #if display
+							   checks. The reasoning is that non-display mode has more information than display mode. *)
+							if not com2.display.dms_display then raise Not_found;
+							let ident = Hashtbl.find Parser.special_identifier_files ffile in
+							Printf.sprintf "not cached, using \"%s\" define" ident,true
+						with Not_found ->
+							CompilationServer.cache_file cs fkey ftime data;
+							"cached",false
+					end in
+					if is_unusual then ServerMessage.parsed com2 "" (ffile,info);
+					data
+			) () in
 			data
 			data
 	);
 	);
 	let check_module_shadowing com paths m =
 	let check_module_shadowing com paths m =