mirror of
https://github.com/apple/swift-nio-http2
synced 2026-11-29 05:24:22 +00:00
Apply swift-format changes and CI (#472)
Motivation: Standardised formatting makes the project cleaner to look at and work on. Modifications: Setup swift-format with the same settings as Swift-NIO Result: Common formatting throughout
This commit is contained in:
1 parent
93586110f2
commit
1118370ec4
125 files changed
+21869
-11457
No files matched your search
@@ -16,7 +16,6 @@ import Foundation
|
||||
import NIOCore
|
||||
import NIOHPACK
|
||||
|
||||
|
||||
/// This benchmark is mostly attempting to stress the Huffman Decoding implementation by
|
||||
/// way of using larger or more complex strings.
|
||||
final class HuffmanDecodingBenchmark {
|
||||
@@ -27,7 +26,11 @@ final class HuffmanDecodingBenchmark {
|
||||
|
||||
init(huffmanBytes: TestType, loopCount: Int) {
|
||||
self.loopCount = loopCount
|
||||
self.decoder = HPACKDecoder(allocator: .init(), maxDynamicTableSize: HPACKDecoder.maxDynamicTableSize, maxHeaderListSize: .max)
|
||||
self.decoder = HPACKDecoder(
|
||||
allocator: .init(),
|
||||
maxDynamicTableSize: HPACKDecoder.maxDynamicTableSize,
|
||||
maxHeaderListSize: .max
|
||||
)
|
||||
self.buffer = ByteBufferAllocator().buffer(capacity: 1024)
|
||||
self.testType = huffmanBytes
|
||||
}
|
||||
@@ -47,21 +50,21 @@ final class HuffmanDecodingBenchmark {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension HuffmanDecodingBenchmark: Benchmark {
|
||||
func setUp() throws {
|
||||
// We encode this header with both the name and value as a huffman string, never indexed.
|
||||
self.buffer.writeInteger(UInt8(0x10)) // Never indexed, non-indexed name
|
||||
self.buffer.encodeInteger(1, prefix: 7, prefixBits: 0x80) // Name length, huffman encoded, 7-bit integer
|
||||
self.buffer.writeInteger(UInt8(0x97)) // Huffman encoded "f"
|
||||
self.buffer.encodeInteger(UInt(self.testType.huffmanBytes.count), prefix: 7, prefixBits: 0x80) // Value length, huffman encoded, 7-bit integer
|
||||
// Value length, huffman encoded, 7-bit integer
|
||||
self.buffer.encodeInteger(UInt(self.testType.huffmanBytes.count), prefix: 7, prefixBits: 0x80)
|
||||
self.buffer.writeBytes(self.testType.huffmanBytes)
|
||||
|
||||
// Run a single iteration of the loop. This warms up the encoder and decoder and ensures all the pages are mapped.
|
||||
try self.loopIteration()
|
||||
}
|
||||
|
||||
func tearDown() { }
|
||||
func tearDown() {}
|
||||
|
||||
func run() throws -> Int {
|
||||
for _ in 0..<self.loopCount {
|
||||
@@ -77,7 +80,6 @@ extension HuffmanDecodingBenchmark: Benchmark {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extension Array where Element == UInt8 {
|
||||
static let basicHuffmanBytes: [UInt8] = {
|
||||
// This is hilariously slow (TWO intermediate Data objects!) but it's only invoked in setup so who cares?
|
||||
@@ -95,10 +97,12 @@ extension Array where Element == UInt8 {
|
||||
}()
|
||||
|
||||
// The location of the test fixtures.
|
||||
private static let fixtureDirectoryURL = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("Tests").appendingPathComponent("NIOHPACKTests").appendingPathComponent("Fixtures").absoluteURL
|
||||
private static let fixtureDirectoryURL = URL(fileURLWithPath: #filePath).deletingLastPathComponent()
|
||||
.deletingLastPathComponent().deletingLastPathComponent().appendingPathComponent("Tests").appendingPathComponent(
|
||||
"NIOHPACKTests"
|
||||
).appendingPathComponent("Fixtures").absoluteURL
|
||||
}
|
||||
|
||||
|
||||
extension ByteBuffer {
|
||||
// Copied directly from our internal implementation.
|
||||
fileprivate mutating func encodeInteger(_ value: UInt, prefix: Int, prefixBits: UInt8 = 0) {
|
||||
|
||||
Reference in new issue
Block a user