Skip to content

Commit 026d996

Browse files
authored
Merge branch 'develop' into master
2 parents eb04353 + d8d08fe commit 026d996

3 files changed

Lines changed: 53 additions & 7 deletions

File tree

src/Giraffe.ViewEngine/Engine.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module HtmlElements =
3535
| KeyValue of string * string
3636
| Boolean of string
3737

38-
type XmlElement = string * XmlAttribute[] // Name * XML attributes
38+
type XmlElement = (struct(string * XmlAttribute list)) // Name * XML attributes
3939

4040
type XmlNode =
4141
| ParentNode of XmlElement * XmlNode list // An XML element which contains nested XML elements
@@ -58,11 +58,11 @@ module HtmlElements =
5858
let tag (tagName : string)
5959
(attributes : XmlAttribute list)
6060
(contents : XmlNode list) =
61-
ParentNode ((tagName, Array.ofList attributes), contents)
61+
ParentNode ((tagName, attributes), contents)
6262

6363
let voidTag (tagName : string)
6464
(attributes : XmlAttribute list) =
65-
VoidElement (tagName, Array.ofList attributes)
65+
VoidElement (tagName, attributes)
6666

6767
/// <summary>
6868
///
@@ -554,21 +554,21 @@ module internal ViewBuilder =
554554

555555
let rec internal buildNode (isHtml : bool) (sb : StringBuilder) (node : XmlNode) : unit =
556556

557-
let buildElement closingBracket (elemName, attributes : XmlAttribute array) =
557+
let buildElement closingBracket struct(elemName, attributes : XmlAttribute list) =
558558
match attributes with
559-
| [||] -> do sb += "<" += elemName +! closingBracket
559+
| [] -> do sb += "<" += elemName +! closingBracket
560560
| _ ->
561561
do sb += "<" +! elemName
562562

563563
attributes
564-
|> Array.iter (fun attr ->
564+
|> List.iter (fun attr ->
565565
match attr with
566566
| KeyValue (k, v) -> do sb += " " += k += "=\"" += v +! "\""
567567
| Boolean k -> do sb += " " +! k)
568568

569569
do sb +! closingBracket
570570

571-
let inline buildParentNode (elemName, attributes : XmlAttribute array) (nodes : XmlNode list) =
571+
let inline buildParentNode struct(elemName, attributes : XmlAttribute list) (nodes : XmlNode list) =
572572
do buildElement ">" (elemName, attributes)
573573
for node in nodes do buildNode isHtml sb node
574574
do sb += "</" += elemName +! ">"

tests/Giraffe.ViewEngine.Benchmarks/Giraffe.ViewEngine.Benchmarks.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>net6.0</TargetFramework>
4+
<OutputType>Exe</OutputType>
45
</PropertyGroup>
56

67
<ItemGroup>

tests/Giraffe.ViewEngine.Benchmarks/Program.fs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,51 @@ type HtmlUtf8Benchmark() =
6868
ArrayPool<char>.Shared.Return(chars)
6969
stringBuilder.Clear()
7070

71+
[<MemoryDiagnoser>]
72+
type HtmlBuildBenchmark() =
73+
74+
let doc() =
75+
div [] [
76+
div [ _class "top-bar" ]
77+
[ div [ _class "top-bar-left" ]
78+
[ ul [ _class "dropdown menu"
79+
_data "dropdown-menu" "" ]
80+
[ li [ _class "menu-text" ]
81+
[ rawText "Site Title" ]
82+
li [ ]
83+
[ a [ _href "#" ]
84+
[ str """One <script>alert("hello world")</script>""" ]
85+
ul [ _class "menu vertical" ]
86+
[ li [ ]
87+
[ a [ _href "#" ]
88+
[ rawText "One" ] ]
89+
li [ ]
90+
[ a [ _href "#" ]
91+
[ str "Two" ] ]
92+
li [ ]
93+
[ a [ _href "#" ]
94+
[ rawText "Three" ] ] ] ]
95+
li [ ]
96+
[ a [ _href "#" ]
97+
[ str "Two" ] ]
98+
li [ ]
99+
[ a [ _href "#" ]
100+
[ str "Three" ] ] ] ]
101+
div [ _class "top-bar-right" ]
102+
[ ul [ _class "menu" ]
103+
[ li [ ]
104+
[ input [ _type "search"
105+
_placeholder "Search" ] ]
106+
li [ ]
107+
[ button [ _type "button"
108+
_class "button" ]
109+
[ rawText "Search" ] ] ] ] ]
110+
]
111+
112+
[<Benchmark( Baseline = true )>]
113+
member this.Default() =
114+
doc()
115+
71116
[<EntryPoint>]
72117
let main args =
73118
let asm = typeof<HtmlUtf8Benchmark>.Assembly

0 commit comments

Comments
 (0)