diff --git a/Sources/Capsule/PersistentDictionary.swift b/Sources/Capsule/PersistentDictionary.swift index d76c0a9c..302f7fe8 100644 --- a/Sources/Capsule/PersistentDictionary.swift +++ b/Sources/Capsule/PersistentDictionary.swift @@ -202,18 +202,8 @@ public struct DictionaryKeyValueTupleIterator: IteratorPro trieIteratorStackRemainder = [] trieIteratorStackRemainder.reserveCapacity(maxDepth) - if rootNode.hasNodes { trieIteratorStackTop = makeTrieIterator(rootNode) } - if rootNode.hasPayload { payloadIterator = makePayloadIterator(rootNode) } - } - - // TODO consider moving to `BitmapIndexedDictionaryNode` - private func makePayloadIterator(_ node: BitmapIndexedDictionaryNode) -> UnsafeBufferPointer<(key: Key, value: Value)>.Iterator { - UnsafeBufferPointer(start: node.dataBaseAddress, count: node.payloadArity).makeIterator() - } - - // TODO consider moving to `BitmapIndexedDictionaryNode` - private func makeTrieIterator(_ node: BitmapIndexedDictionaryNode) -> UnsafeBufferPointer>.Iterator { - UnsafeBufferPointer(start: node.trieBaseAddress, count: node.nodeArity).makeIterator() + if rootNode.hasNodes { trieIteratorStackTop = rootNode._trieSlice.makeIterator() } + if rootNode.hasPayload { payloadIterator = rootNode._dataSlice.makeIterator() } } public mutating func next() -> (key: Key, value: Value)? { @@ -225,10 +215,10 @@ public struct DictionaryKeyValueTupleIterator: IteratorPro if let nextNode = trieIteratorStackTop!.next() { if nextNode.hasNodes { trieIteratorStackRemainder.append(trieIteratorStackTop!) - trieIteratorStackTop = makeTrieIterator(nextNode) + trieIteratorStackTop = nextNode._trieSlice.makeIterator() } if nextNode.hasPayload { - payloadIterator = makePayloadIterator(nextNode) + payloadIterator = nextNode._dataSlice.makeIterator() return payloadIterator?.next() } } else { diff --git a/Sources/Capsule/_BitmapIndexedDictionaryNode.swift b/Sources/Capsule/_BitmapIndexedDictionaryNode.swift index 2d747976..99403f91 100644 --- a/Sources/Capsule/_BitmapIndexedDictionaryNode.swift +++ b/Sources/Capsule/_BitmapIndexedDictionaryNode.swift @@ -120,14 +120,12 @@ final class BitmapIndexedDictionaryNode: DictionaryNode where Key: H (header.dataMap & header.trieMap) == 0 || (header.dataMap == header.trieMap) } - // TODO: should not materialize as `Array` for performance reasons - var _dataSlice: [DataBufferElement] { - UnsafeMutableBufferPointer(start: dataBaseAddress, count: header.dataCount).map { $0 } + var _dataSlice: UnsafeBufferPointer { + UnsafeBufferPointer(start: dataBaseAddress, count: header.dataCount) } - // TODO: should not materialize as `Array` for performance reasons - var _trieSlice: [TrieBufferElement] { - UnsafeMutableBufferPointer(start: trieBaseAddress, count: header.trieCount).map { $0 } + var _trieSlice: UnsafeMutableBufferPointer { + UnsafeMutableBufferPointer(start: trieBaseAddress, count: header.trieCount) } init(dataCapacity: Capacity, trieCapacity: Capacity) {