Skip to content

Commit

Permalink
Holmake: cache/memoise results of wildcard function
Browse files Browse the repository at this point in the history
I noticed that this was being called an awful lot while debugging
something else.
  • Loading branch information
mn200 committed Aug 15, 2022
1 parent f72dd5a commit 4dc3e64
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tools/Holmake/internal_functions.sml
Expand Up @@ -185,7 +185,7 @@ fun safeIsDir s =

fun diag s = TextIO.output(TextIO.stdErr, s)

fun wildcard s =
fun wildcard0 (dirname,s) =
if s = "" then [""]
else let
open parse_glob
Expand All @@ -198,7 +198,7 @@ fun wildcard s =
else k (d,"", l)
| [] => k (d,"", l)
val (starting_dir,pfx, rest) =
initial_split (FileSys.getDir()) split_comps (fn x => x)
initial_split dirname split_comps (fn x => x)
fun recurse curpfx curdir complist : string list =
case complist of
c::cs => (* c must be non-null *)
Expand Down Expand Up @@ -242,6 +242,13 @@ fun wildcard s =
| _ => case recurse pfx starting_dir rest of [] => [] | x => x
end

local open Holmake_tools
val wildcard_withdir =
memoise (pair_compare(String.compare, String.compare)) wildcard0
in
fun wildcard s = wildcard_withdir (OS.FileSys.getDir(), s)
end

fun get_first f [] = NONE
| get_first f (h::t) = (case f h of NONE => get_first f t | x => x)

Expand Down

0 comments on commit 4dc3e64

Please sign in to comment.