diff --git a/Sources/HashTreeCollections/HashNode/_HashNode+Storage.swift b/Sources/HashTreeCollections/HashNode/_HashNode+Storage.swift index 0aefeb848..44854293e 100644 --- a/Sources/HashTreeCollections/HashNode/_HashNode+Storage.swift +++ b/Sources/HashTreeCollections/HashNode/_HashNode+Storage.swift @@ -77,10 +77,15 @@ extension _HashNode.Storage { bytes += itemAlignment - childAlignment } + let mincap = (bytes &+ childStride &- 1) / childStride let object = _HashNode.Storage.create( - minimumCapacity: (bytes &+ childStride &- 1) / childStride + minimumCapacity: mincap ) { buffer in +#if os(OpenBSD) + _HashNodeHeader(byteCapacity: mincap * childStride) +#else _HashNodeHeader(byteCapacity: buffer.capacity * childStride) +#endif } object.withUnsafeMutablePointers { header, elements in diff --git a/Sources/HashTreeCollections/HashNode/_HashTreeStatistics.swift b/Sources/HashTreeCollections/HashNode/_HashTreeStatistics.swift index 85468af5f..0dd1efedc 100644 --- a/Sources/HashTreeCollections/HashNode/_HashTreeStatistics.swift +++ b/Sources/HashTreeCollections/HashNode/_HashTreeStatistics.swift @@ -118,8 +118,7 @@ extension _HashNode { // Note: for simplicity, we assume that there is no padding between // the object header and the storage header. let start = _getUnsafePointerToStoredProperties(self.raw.storage) - let capacity = self.raw.storage.capacity - let end = $0._memory + capacity * MemoryLayout<_RawHashNode>.stride + let end = $0._memory + $0.byteCapacity stats.grossBytes += objectHeaderSize + (end - start) for child in $0.children {