diff --git a/Sources/DequeModule/DynamicDeque.swift b/Sources/DequeModule/DynamicDeque.swift index c4ad8ef1..4e6156b2 100644 --- a/Sources/DequeModule/DynamicDeque.swift +++ b/Sources/DequeModule/DynamicDeque.swift @@ -86,7 +86,7 @@ extension DynamicDeque where Element: ~Copyable { @inlinable internal mutating func _grow(to minimumCapacity: Int) { guard minimumCapacity > _capacity else { return } - let c = Swift.max(minimumCapacity, 2 * _capacity) + let c = Swift.max(minimumCapacity, 7 * _capacity / 4) _storage.resize(to: c) } diff --git a/Sources/Future/Containers/Container.swift b/Sources/Future/Containers/Container.swift index b4d5a5be..3473efb9 100644 --- a/Sources/Future/Containers/Container.swift +++ b/Sources/Future/Containers/Container.swift @@ -33,6 +33,7 @@ public protocol Container: ~Copyable, ~Escapable { var endIndex: Index { get } // FIXME: Replace `@_borrowed` with proper `read`/`modify` accessor requirements + // FIXME: (Or rather, accessors with proper projection semantics.) @_borrowed subscript(index: Index) -> Element { get } func index(after index: Index) -> Index diff --git a/Sources/Future/Containers/DynamicArray.swift b/Sources/Future/Containers/DynamicArray.swift index b84787aa..0da61708 100644 --- a/Sources/Future/Containers/DynamicArray.swift +++ b/Sources/Future/Containers/DynamicArray.swift @@ -40,8 +40,8 @@ extension DynamicArray where Element: ~Copyable { } extension DynamicArray where Element: ~Copyable { - public var span: Span { - _storage.span + public var storage: Span { + _storage.storage } } diff --git a/Sources/Future/Containers/NewArray.swift b/Sources/Future/Containers/NewArray.swift index 4e89aeb5..8c9b0111 100644 --- a/Sources/Future/Containers/NewArray.swift +++ b/Sources/Future/Containers/NewArray.swift @@ -21,6 +21,17 @@ public struct NewArray { } } +extension NewArray { + public var storage: Span { +#if false + // FIXME: This is what I want to write; alas, lifetimes are messed up. + return _storage.value.storage +#else + return Span(unsafeElements: _storage.value._items, owner: self) +#endif + } +} + extension NewArray { @inlinable public var capacity: Int { _storage.read { $0.capacity } } @@ -31,7 +42,10 @@ extension NewArray { } @inlinable - internal mutating func _ensureUnique(minimumCapacity: Int) { + internal mutating func _ensureUnique( + minimumCapacity: Int, + linear: Bool = false + ) { if !_storage.isUnique() { let c = Swift.max(count, minimumCapacity) _storage = Shared(_storage.read { $0._copy(capacity: c) }) @@ -88,8 +102,17 @@ extension NewArray: RandomAccessCollection, MutableCollection { } } -extension NewArray { - public var span: Span { - Span(unsafeElements: _storage.value._items, owner: self) +extension NewArray: RangeReplaceableCollection { + public init() { + // FIXME: Figure out if we can implement empty singletons in this setup. + self._storage = Shared(RigidArray(capacity: 0)) + } + + public func replaceSubrange( + _ subrange: Range, + with newElements: some Collection + ) { + let delta = newElements.count - subrange.count + _ensureUnique(minimumCapacity: capacity + delta) } } diff --git a/Sources/Future/Containers/RigidArray.swift b/Sources/Future/Containers/RigidArray.swift index adc654eb..5d190222 100644 --- a/Sources/Future/Containers/RigidArray.swift +++ b/Sources/Future/Containers/RigidArray.swift @@ -59,7 +59,7 @@ extension RigidArray where Element: ~Copyable { } extension RigidArray where Element: ~Copyable { - public var span: Span { + public var storage: Span { Span(unsafeElements: _items, owner: self) } }