Skip to content

Commit

Permalink
Reduced some dictionary double-lookups (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorium authored Nov 30, 2023
1 parent dc62a7e commit 8511856
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/Saturn/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ module Common =
let private getSavedSubPath (ctx : HttpContext) =
let inline strOption (str : string) =
if String.IsNullOrEmpty str then None else Some str
if ctx.Items.ContainsKey RouteKey
then ctx.Items.Item RouteKey |> string |> strOption
else None
match ctx.Items.TryGetValue RouteKey with
| true, route -> route |> string |> strOption
| false, _ -> None

let private handlerWithRootedPath (path : string) (handler : HttpHandler) : HttpHandler =
fun (next : HttpFunc) (ctx : HttpContext) ->
Expand Down
7 changes: 3 additions & 4 deletions src/Saturn/Controller.fs
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,9 @@ module Controller =
member __.Plug(state, actions, handler) =
let addPlug state action handler =
let newplugs =
if state.Plugs.ContainsKey action then
state.Plugs.Add(action, (handler::state.Plugs.[action]))
else
state.Plugs.Add(action,[handler])
match state.Plugs.TryGetValue action with
| true, acts -> state.Plugs.Add(action, (handler::acts))
| false, _ -> state.Plugs.Add(action,[handler])
{state with Plugs = newplugs}

if actions |> List.contains All then
Expand Down
7 changes: 3 additions & 4 deletions src/Saturn/ControllerEndpoint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,9 @@ module Controller =
member __.Plug(state, actions, handler) =
let addPlug state action handler =
let newplugs =
if state.Plugs.ContainsKey action then
state.Plugs.Add(action, (handler::state.Plugs.[action]))
else
state.Plugs.Add(action,[handler])
match state.Plugs.TryGetValue action with
| true, acts -> state.Plugs.Add(action, (handler::acts))
| false, _ -> state.Plugs.Add(action,[handler])
{state with Plugs = newplugs}

if actions |> List.contains All then
Expand Down

0 comments on commit 8511856

Please sign in to comment.