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

Implement TinyArray #98

Merged
merged 12 commits into from
Jun 20, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@
//
//===----------------------------------------------------------------------===//

import X509
@_spi(IntegrationTests) import X509

func run(identifier: String) {
measure(identifier: identifier) {
return 0
var array = Array<Int>()
array.reserveCapacity(4)
array.append(1)
array.append(2)
var tinyArray = TinyArray(array)
// drop the ref to array so TinyArray is now the single owner
array = []

tinyArray.append(3)
tinyArray.append(4)
return tinyArray.count
}
dnadoba marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftCertificates open source project
//
// Copyright (c) 2023 Apple Inc. and the SwiftCertificates project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftCertificates project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

@_spi(IntegrationTests) import X509

func run(identifier: String) {
let preallocatedArray1 = [1]
let preallocatedArray2 = [1, 2]
let preallocatedArray3 = [1, 2, 3]
let preallocatedArray4 = [1, 2, 3, 4]

measure(identifier: identifier) {
var counts = 0
counts += TinyArray(CollectionOfOne(1)).count
counts += TinyArray(preallocatedArray1).count
counts += TinyArray(preallocatedArray2).count
counts += TinyArray(preallocatedArray3).count
counts += TinyArray(preallocatedArray4).count

do {
dnadoba marked this conversation as resolved.
Show resolved Hide resolved
var array = TinyArray<Int>()
array.append(contentsOf: CollectionOfOne(1))
counts += array.count
}

do {
var array = TinyArray<Int>()
array.append(contentsOf: preallocatedArray1)
counts += array.count
}

do {
var array = TinyArray<Int>()
array.append(contentsOf: preallocatedArray2)
counts += array.count
}

do {
var array = TinyArray<Int>()
array.append(contentsOf: preallocatedArray3)
counts += array.count
}

do {
var array = TinyArray<Int>()
array.append(contentsOf: preallocatedArray4)
counts += array.count
}

return counts
}
}
1 change: 1 addition & 0 deletions Sources/X509/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ add_library(X509
"SEC1PrivateKey.swift"
"Signature.swift"
"SignatureAlgorithm.swift"
"TinyArray.swift"
"Verifier/AnyPolicy.swift"
"Verifier/CertificateStore.swift"
"Verifier/PolicyBuilder.swift"
Expand Down