-
Notifications
You must be signed in to change notification settings - Fork 230
Remove swift-collections dependency #948
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a00acd9
Update swift-collections package version range
dfed 70d1562
Apply suggestion from @dfed
dfed f4afb6d
Package@swift-6.0.swift too
dfed 2e5aa8d
Remove swift-collections dependency
dfed 11dce9d
Add .changes entry for swift-collections removal
dfed 8ba9363
Remove redundant license line from attribution comments
dfed 1b63c05
Use circular buffer for Deque to ensure O(1) removeFirst
dfed 6f144a8
Apply review feedback from pblazej
dfed d5da9f1
Remove swift-collections from Package@swift-6.2.swift
dfed df498fe
Run swiftformat to fix redundantSendable and sortImports lint
dfed 7ee3b98
Regenerate protobuf files with latest swift-protobuf
dfed 552d4e8
Trigger CI re-run
dfed 1739e43
Merge branch 'main' into patch-1
pblazej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| patch type="changed" "Remove swift-collections dependency by replacing with minimal internal implementations" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,6 @@ | |
|
|
||
| // swiftlint:disable file_length | ||
|
|
||
| import DequeModule | ||
| import Foundation | ||
|
|
||
| internal import LiveKitWebRTC | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Copyright 2026 LiveKit | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // API inspired by swift-collections by Apple Inc. | ||
| // https://github.com/apple/swift-collections | ||
|
|
||
| /// A double-ended queue backed by a circular buffer. | ||
| /// Provides O(1) amortized `append` and `removeFirst`. | ||
| struct Deque<Element>: ExpressibleByArrayLiteral { | ||
| private var buffer: [Element?] = [] | ||
|
dfed marked this conversation as resolved.
|
||
| private var head = 0 | ||
| private var count_ = 0 | ||
|
|
||
| init() {} | ||
|
|
||
| init(arrayLiteral elements: Element...) { | ||
| buffer = elements.map { $0 } | ||
| count_ = elements.count | ||
| } | ||
|
|
||
| var isEmpty: Bool { count_ == 0 } | ||
|
|
||
| var first: Element? { | ||
| guard count_ > 0 else { return nil } | ||
| return buffer[head] | ||
| } | ||
|
|
||
| mutating func append(_ element: Element) { | ||
| if count_ == buffer.count { | ||
| grow() | ||
| } | ||
| let tail = (head + count_) & (buffer.count - 1) | ||
| buffer[tail] = element | ||
| count_ += 1 | ||
| } | ||
|
|
||
| @discardableResult | ||
| mutating func removeFirst() -> Element { | ||
| guard count_ > 0 else { | ||
| preconditionFailure("Cannot removeFirst from an empty Deque") | ||
| } | ||
| let element = buffer[head]! | ||
| buffer[head] = nil | ||
| head = (head + 1) & (buffer.count - 1) | ||
| count_ -= 1 | ||
| return element | ||
| } | ||
|
|
||
| private mutating func grow() { | ||
| let newCapacity = max(buffer.count * 2, 4) | ||
| var newBuffer = [Element?](repeating: nil, count: newCapacity) | ||
| let mask = buffer.count - 1 | ||
| for i in 0 ..< count_ { | ||
| newBuffer[i] = buffer[(head + i) & mask] | ||
| } | ||
|
dfed marked this conversation as resolved.
|
||
| buffer = newBuffer | ||
| head = 0 | ||
| } | ||
| } | ||
|
|
||
| extension Deque: Sendable where Element: Sendable {} | ||
97 changes: 97 additions & 0 deletions
97
Sources/LiveKit/Support/DataStructures/OrderedDictionary.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /* | ||
| * Copyright 2026 LiveKit | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // API inspired by swift-collections by Apple Inc. | ||
| // https://github.com/apple/swift-collections | ||
|
|
||
| struct OrderedDictionary<Key: Hashable, Value>: ExpressibleByDictionaryLiteral { | ||
| private var pairs: [(key: Key, value: Value)] = [] | ||
| private var index: [Key: Int] = [:] | ||
|
pblazej marked this conversation as resolved.
|
||
|
|
||
| init() {} | ||
|
|
||
| init(dictionaryLiteral elements: (Key, Value)...) { | ||
| for (key, value) in elements { | ||
| pairs.append((key, value)) | ||
| index[key] = pairs.count - 1 | ||
| } | ||
| } | ||
|
|
||
| init(uniqueKeysWithValues keysAndValues: some Sequence<(Key, Value)>) { | ||
|
dfed marked this conversation as resolved.
|
||
| for (key, value) in keysAndValues { | ||
| if let i = index[key] { | ||
| pairs[i] = (key, value) | ||
| } else { | ||
| index[key] = pairs.count | ||
| pairs.append((key, value)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| var count: Int { pairs.count } | ||
|
|
||
| var keys: Keys { Keys(pairs: pairs) } | ||
| var values: Values { Values(pairs: pairs) } | ||
|
|
||
| subscript(key: Key) -> Value? { | ||
| get { | ||
| guard let i = index[key] else { return nil } | ||
| return pairs[i].value | ||
| } | ||
| set { | ||
| if let newValue { | ||
| if let i = index[key] { | ||
| pairs[i] = (key, newValue) | ||
| } else { | ||
| index[key] = pairs.count | ||
| pairs.append((key, newValue)) | ||
| } | ||
| } else if let i = index.removeValue(forKey: key) { | ||
| pairs.remove(at: i) | ||
| for j in i ..< pairs.count { | ||
| index[pairs[j].key] = j | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @discardableResult | ||
| mutating func updateValue(_ value: Value, forKey key: Key) -> Value? { | ||
| if let i = index[key] { | ||
| let old = pairs[i].value | ||
| pairs[i] = (key, value) | ||
| return old | ||
| } | ||
| index[key] = pairs.count | ||
| pairs.append((key, value)) | ||
| return nil | ||
| } | ||
|
|
||
| struct Keys { | ||
| fileprivate let pairs: [(key: Key, value: Value)] | ||
| subscript(position: Int) -> Key { pairs[position].key } | ||
| } | ||
|
|
||
| struct Values { | ||
| fileprivate let pairs: [(key: Key, value: Value)] | ||
| var elements: [Value] { pairs.map(\.value) } | ||
| subscript(position: Int) -> Value { pairs[position].value } | ||
| } | ||
| } | ||
|
|
||
| extension OrderedDictionary: Sendable where Key: Sendable, Value: Sendable {} | ||
| extension OrderedDictionary.Keys: Sendable where Key: Sendable, Value: Sendable {} | ||
| extension OrderedDictionary.Values: Sendable where Key: Sendable, Value: Sendable {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright 2026 LiveKit | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| // API inspired by swift-collections by Apple Inc. | ||
| // https://github.com/apple/swift-collections | ||
|
|
||
| struct OrderedSet<Element: Hashable> { | ||
| private var array: [Element] = [] | ||
| private var set: [Element: Int] = [:] | ||
|
pblazej marked this conversation as resolved.
|
||
|
|
||
| init() {} | ||
|
|
||
| var elements: [Element] { array } | ||
|
|
||
| @discardableResult | ||
| mutating func append(_ element: Element) -> (inserted: Bool, index: Int) { | ||
| if let existing = set[element] { | ||
| return (inserted: false, index: existing) | ||
| } | ||
| let index = array.count | ||
| array.append(element) | ||
| set[element] = index | ||
| return (inserted: true, index: index) | ||
| } | ||
| } | ||
|
|
||
| extension OrderedSet: Sendable where Element: Sendable {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,6 @@ | |
| */ | ||
|
|
||
| import Foundation | ||
| import OrderedCollections | ||
|
|
||
| // MARK: - Triggers | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.