Skip to content

Commit

Permalink
ManagedBuffer et al: Value => Header
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Abrahams committed Jun 22, 2016
1 parent 85f665f commit eb7311d
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 110 deletions.
20 changes: 10 additions & 10 deletions stdlib/public/core/ContiguousArrayBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {

deinit {
__manager._elementPointer.deinitialize(
count: __manager._valuePointer.pointee.count)
__manager._valuePointer.deinitialize()
count: __manager._headerPointer.pointee.count)
__manager._headerPointer.deinitialize()
_fixLifetime(__manager)
}

Expand All @@ -114,7 +114,7 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
invoke body: @noescape (UnsafeBufferPointer<AnyObject>) throws -> Void
) rethrows {
if _isBridgedVerbatimToObjectiveC(Element.self) {
let count = __manager.value.count
let count = __manager.header.count
let elements = UnsafePointer<AnyObject>(__manager._elementPointer)
defer { _fixLifetime(__manager) }
try body(UnsafeBufferPointer(start: elements, count: count))
Expand All @@ -128,7 +128,7 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
_sanityCheck(
!_isBridgedVerbatimToObjectiveC(Element.self),
"Verbatim bridging should be handled separately")
return __manager.value.count
return __manager.header.count
}

/// Bridge array elements and return a new buffer that owns them.
Expand All @@ -139,7 +139,7 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
_sanityCheck(
!_isBridgedVerbatimToObjectiveC(Element.self),
"Verbatim bridging should be handled separately")
let count = __manager.value.count
let count = __manager.header.count
let result = _HeapBuffer<Int, AnyObject>(
_HeapBufferStorage<Int, AnyObject>.self, count, count)
let resultPtr = result.baseAddress
Expand Down Expand Up @@ -238,7 +238,7 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
let verbatim = false
#endif

__bufferPointer._valuePointer.initialize(with:
__bufferPointer._headerPointer.initialize(with:
_ArrayBody(
count: count,
capacity: capacity,
Expand Down Expand Up @@ -342,7 +342,7 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
/// The number of elements the buffer stores.
public var count: Int {
get {
return __bufferPointer.value.count
return __bufferPointer.header.count
}
nonmutating set {
_sanityCheck(newValue >= 0)
Expand All @@ -351,7 +351,7 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
newValue <= capacity,
"Can't grow an array buffer past its capacity")

__bufferPointer._valuePointer.pointee.count = newValue
__bufferPointer._headerPointer.pointee.count = newValue
}
}

Expand All @@ -360,14 +360,14 @@ public struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
@inline(__always)
func _checkValidSubscript(_ index : Int) {
_precondition(
(index >= 0) && (index < __bufferPointer.value.count),
(index >= 0) && (index < __bufferPointer.header.count),
"Index out of range"
)
}

/// The number of elements the buffer can store without reallocation.
public var capacity: Int {
return __bufferPointer.value.capacity
return __bufferPointer.header.capacity
}

/// Copy the elements in `bounds` from this buffer into uninitialized
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/core/HashedCollections.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2505,10 +2505,10 @@ final internal class _Native${Self}StorageImpl<${TypeParameters}> :
// All underscored functions are unsafe and need a _fixLifetime in the caller.
internal var _body: _HashedContainerStorageHeader {
unsafeAddress {
return UnsafePointer(buffer._valuePointer)
return UnsafePointer(buffer._headerPointer)
}
unsafeMutableAddress {
return buffer._valuePointer
return buffer._headerPointer
}
}

Expand Down Expand Up @@ -2601,7 +2601,7 @@ final internal class _Native${Self}StorageImpl<${TypeParameters}> :
}
}
%end
buffer._valuePointer.deinitialize()
buffer._headerPointer.deinitialize()
_fixLifetime(self)
}
}
Expand Down
Loading

0 comments on commit eb7311d

Please sign in to comment.