minor performance tuning; directly try to read file instead of first checking its existence
authordesharna
Thu, 19 Dec 2024 16:01:06 +0100
changeset 81635 362b2ff84206
parent 81634 5617622681d7
child 81637 445d27ab591b
minor performance tuning; directly try to read file instead of first checking its existence
src/HOL/Tools/Sledgehammer/sledgehammer.ML
--- a/src/HOL/Tools/Sledgehammer/sledgehammer.ML	Thu Dec 19 08:26:04 2024 +0100
+++ b/src/HOL/Tools/Sledgehammer/sledgehammer.ML	Thu Dec 19 16:01:06 2024 +0100
@@ -494,23 +494,20 @@
     val hash = SHA1.rep (SHA1.digest arg)
     val file = cache_dir + Path.explode hash
   in
-    if File.is_file file then
+    (case try File.read file of
+      NONE => 
+      let val result = f arg in
+        File.write file result;
+        result
+      end
+    | SOME s =>
       let
         val () =
           if verbose then
             writeln ("Found problem with key " ^ hash ^ " in cache.")
           else
             ()
-      in
-        File.read file
-      end
-    else
-      let
-        val result = f arg
-      in
-        File.write file result;
-        result
-      end
+      in s end)
   end
 in