Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduced some dictionary double-lookups #378

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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