Skip to content

Commit 7379ac0

Browse files
disable HTMLResultRepresentation.literalOptimized for now as it doesn't perform as expected
- benchmark updates
1 parent 2e6a0d9 commit 7379ac0

File tree

21 files changed

+131
-80
lines changed

21 files changed

+131
-80
lines changed

Benchmarks/Benchmarks/Benchmarks/Benchmarks.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let benchmarks = {
3636
}
3737
}*/
3838

39-
let context:HTMLContext = HTMLContext()
39+
let context = HTMLContext()
4040
for (key, value) in libraries {
4141
Benchmark(key) {
4242
for _ in $0.scaledIterations {

Benchmarks/Benchmarks/Elementary/Elementary.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Utilities
33
import Elementary
44

5-
package struct ElementaryTests : HTMLGenerator {
5+
package struct ElementaryTests: HTMLGenerator {
66
package init() {}
77

88
package func staticHTML() -> String {
@@ -14,8 +14,8 @@ package struct ElementaryTests : HTMLGenerator {
1414
}
1515
}
1616

17-
struct StaticView : HTML {
18-
var content : some HTML {
17+
struct StaticView: HTML {
18+
var content: some HTML {
1919
HTMLRaw("<!DOCTYPE html>")
2020
html {
2121
head {
@@ -28,10 +28,10 @@ struct StaticView : HTML {
2828
}
2929
}
3030

31-
struct DynamicView : HTML {
31+
struct DynamicView: HTML {
3232
let context:HTMLContext
3333

34-
var content : some HTML {
34+
var content: some HTML {
3535
HTMLRaw("<!DOCTYPE html>")
3636
html {
3737
head {

Benchmarks/Benchmarks/Plot/Plot.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Utilities
33
import Plot
44

5-
package struct PlotTests : HTMLGenerator {
5+
package struct PlotTests: HTMLGenerator {
66
package init() {}
77

88
package func staticHTML() -> String {

Benchmarks/Benchmarks/SwiftDOM/SwiftDOM.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import Utilities
44
import DOM
55

6-
package struct SwiftDOMTests : HTMLGenerator {
6+
package struct SwiftDOMTests: HTMLGenerator {
77
package init() {}
88

99
package func staticHTML() -> String {
@@ -57,9 +57,5 @@ package struct SwiftDOMTests : HTMLGenerator {
5757
}
5858

5959
// required to compile
60-
extension String:HTML.OutputStreamable
61-
{
62-
}
63-
extension String:SVG.OutputStreamable
64-
{
65-
}
60+
extension String: HTML.OutputStreamable {}
61+
extension String: SVG.OutputStreamable {}

Benchmarks/Benchmarks/SwiftHTMLBB/SwiftHTMLBB.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import Utilities
33
import SwiftHtml
44

5-
package struct SwiftHTMLBBTests : HTMLGenerator {
5+
package struct SwiftHTMLBBTests: HTMLGenerator {
66
let renderer:DocumentRenderer
77
package init() {
88
renderer = DocumentRenderer(minify: true, indent: 0)

Benchmarks/Benchmarks/SwiftHTMLKit/SwiftHTMLKit.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Utilities
33
import SwiftHTMLKit
44
import NIOCore
55

6-
package struct SwiftHTMLKitTests : HTMLGenerator {
6+
package struct SwiftHTMLKitTests: HTMLGenerator {
77
package init() {}
88

99
package func staticHTML() -> String {
@@ -67,9 +67,9 @@ package struct SwiftHTMLKitTests : HTMLGenerator {
6767
package func dynamicHTML(_ context: HTMLContext) -> String {
6868
var qualities:String = ""
6969
for quality in context.user.qualities {
70-
qualities += #html(li(quality))
70+
qualities += #html(representation: .literal, li(quality))
7171
}
72-
return #html {
72+
return #html(representation: .literal) {
7373
html {
7474
head {
7575
meta(charset: context.charset)

Benchmarks/Benchmarks/Swim/Swim.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import Utilities
33
import Swim
44
import HTML
55

6-
package struct SwimTests : HTMLGenerator {
6+
package struct SwimTests: HTMLGenerator {
77
package init() {}
88

99
package func staticHTML() -> String {
10-
var string:String = ""
10+
var string = ""
1111
html {
1212
head {
1313
title { "StaticView" }
@@ -22,8 +22,9 @@ package struct SwimTests : HTMLGenerator {
2222
}
2323

2424
package func dynamicHTML(_ context: HTMLContext) -> String {
25-
var string:String = ""
26-
var test:[Node] = []
25+
var string = ""
26+
var test = [Node]()
27+
test.reserveCapacity(context.user.qualities.count)
2728
for quality in context.user.qualities {
2829
test.append(li { quality } )
2930
}

Benchmarks/Benchmarks/VaporHTMLKit/VaporHTMLKit.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import Utilities
33
import VaporHTMLKit
44

5-
package struct VaporHTMLKitTests : HTMLGenerator {
5+
package struct VaporHTMLKitTests: HTMLGenerator {
66

77
let renderer:Renderer
8+
89
package init() {
910
renderer = Renderer()
1011
try! renderer.add(layout: StaticView())
@@ -20,7 +21,7 @@ package struct VaporHTMLKitTests : HTMLGenerator {
2021
}
2122

2223
struct StaticView : View {
23-
var body : AnyContent {
24+
var body: AnyContent {
2425
Document(.html5)
2526
Html {
2627
Head {
@@ -36,7 +37,7 @@ struct StaticView : View {
3637
struct DynamicView : View {
3738
let context:Utilities.HTMLContext
3839

39-
var body : AnyContent {
40+
var body: AnyContent {
4041
Document(.html5)
4142
Html {
4243
Head {

Benchmarks/Benchmarks/Vaux/Vaux.swift

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@ import Foundation
55

66
// MARK: Custom rendering
77
extension HTML {
8+
@inlinable
89
func render(includeTag: Bool) -> (HTMLType, String) {
9-
if let node:HTMLNode = self as? HTMLNode {
10+
if let node = self as? HTMLNode {
1011
return (.node, node.rendered(includeTag: includeTag))
11-
} else if let node:MultiNode = self as? MultiNode {
12+
} else if let node = self as? MultiNode {
1213
var string:String = ""
1314
for child in node.children {
1415
string += child.render(includeTag: true).1
1516
}
1617
return (.node, string)
17-
} else if let node:AttributedNode = self as? AttributedNode {
18+
} else if let node = self as? AttributedNode {
1819
return (.node, node.render)
1920
} else {
2021
return (.node, String(describing: self))
2122
}
2223
}
24+
@inlinable
2325
func isVoid(_ tag: String) -> Bool {
2426
switch tag {
2527
case "area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr": return true
@@ -28,31 +30,32 @@ extension HTML {
2830
}
2931
}
3032

31-
enum HTMLType {
33+
public enum HTMLType {
3234
case node, attribute
3335
}
3436

3537
extension AttributedNode {
36-
var render : String {
37-
let tag:String = child.getTag()!
38-
let attribute_string:String = " " + attribute.key + (attribute.value != nil ? "=\"" + attribute.value! + "\"" : "")
38+
@inlinable
39+
var render: String {
40+
let tag = child.getTag()!
41+
let attribute_string = " " + attribute.key + (attribute.value != nil ? "=\"" + attribute.value! + "\"" : "")
3942
return "<" + tag + attribute_string + ">" + child.render(includeTag: false).1 + (isVoid(tag) ? "" : "</" + tag + ">")
4043
}
4144
}
4245

4346
extension HTMLNode {
47+
@inlinable
4448
func rendered(includeTag: Bool) -> String {
45-
guard let tag:String = getTag() else { return String(describing: self) }
46-
var attributes:String = "", children:String = ""
49+
guard let tag = getTag() else { return String(describing: self) }
50+
var attributes = ""
51+
var children = ""
4752
if let child = self.child {
48-
let (type, value):(HTMLType, String) = child.render(includeTag: true)
53+
let (type, value) = child.render(includeTag: true)
4954
switch type {
50-
case .attribute:
51-
attributes += " " + value
52-
break
53-
case .node:
54-
children += value
55-
break
55+
case .attribute:
56+
attributes += " " + value
57+
case .node:
58+
children += value
5659
}
5760
}
5861
return (tag == "html" ? "<!DOCTYPE html>" : "") + (includeTag ? "<" + tag + attributes + ">" : "") + children + (!isVoid(tag) && includeTag ? "</" + tag + ">" : "")

Benchmarks/Package.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// swift-tools-version:5.10
2-
// The swift-tools-version declares the minimum version of Swift required to build this package.
32

43
import PackageDescription
54

@@ -9,7 +8,7 @@ let package = Package(
98
.macOS(.v14)
109
],
1110
dependencies: [
12-
.package(url: "https://github.com/ordo-one/package-benchmark", from: "1.27.0"),
11+
.package(url: "https://github.com/ordo-one/package-benchmark", from: "1.29.3"),
1312
.package(url: "https://github.com/swiftlang/swift-syntax", from: "600.0.0"),
1413
// dsls
1514
.package(name: "swift-htmlkit", path: "../"),

0 commit comments

Comments
 (0)