Switch a bunch of UnsafePointer<T>'s over to T*

Swift SVN r18220
This commit is contained in:
Doug Gregor
2014-05-16 22:32:01 +00:00
parent 39841c3889
commit 73f02d1a69
11 changed files with 46 additions and 46 deletions

View File

@@ -165,8 +165,8 @@ extension ArrayBuffer {
/// starting at target. Return a pointer past-the-end of the /// starting at target. Return a pointer past-the-end of the
/// just-initialized memory. /// just-initialized memory.
func _uninitializedCopy( func _uninitializedCopy(
subRange: Range<Int>, target: UnsafePointer<T> subRange: Range<Int>, target: T*
) -> UnsafePointer<T> { ) -> T* {
if _fastPath(_isNative) { if _fastPath(_isNative) {
return _native._uninitializedCopy(subRange, target: target) return _native._uninitializedCopy(subRange, target: target)
} }
@@ -225,7 +225,7 @@ extension ArrayBuffer {
/// If the elements are stored contiguously, a pointer to the first /// If the elements are stored contiguously, a pointer to the first
/// element. Otherwise, nil. /// element. Otherwise, nil.
var elementStorage: UnsafePointer<T> { var elementStorage: T* {
if (_fastPath(_isNative)) { if (_fastPath(_isNative)) {
return _native.elementStorage return _native.elementStorage
} }

View File

@@ -305,7 +305,7 @@ extension Array {
count: Builtin.Word count: Builtin.Word
) -> Array { ) -> Array {
let elements = UnsafeArray( let elements = UnsafeArray(
start: reinterpretCast(base) as UnsafePointer<T>, start: reinterpretCast(base) as T*,
length: reinterpretCast(count) as Int length: reinterpretCast(count) as Int
) )
let r = Array(elements) let r = Array(elements)
@@ -556,7 +556,7 @@ func _arrayOutOfPlaceUpdate<
} }
struct InitializePointer<T> : PointerFunction { struct InitializePointer<T> : PointerFunction {
func call(rawMemory: UnsafePointer<T>) { func call(rawMemory: T*) {
// FIXME: maybe we should move here instead of copying? // FIXME: maybe we should move here instead of copying?
rawMemory.initialize(newValue) rawMemory.initialize(newValue)
} }

View File

@@ -164,7 +164,7 @@ var _nilRawPointer: Builtin.RawPointer {
/// lvalue), /// lvalue),
/// - an inout argument of the Array<T> type, which gets passed as a pointer /// - an inout argument of the Array<T> type, which gets passed as a pointer
/// to the beginning of the array, /// to the beginning of the array,
/// - an UnsafePointer<T>, which is passed as-is. /// - an T*, which is passed as-is.
/// ///
/// The value consists of an owner-value pair. During bridging, a strong /// The value consists of an owner-value pair. During bridging, a strong
/// reference to the owner is held for the duration of the call, and the pointer /// reference to the owner is held for the duration of the call, and the pointer
@@ -212,7 +212,7 @@ struct CMutablePointer<T> : Equatable {
/// Make the pointer available as an UnsafePointer within a closure. /// Make the pointer available as an UnsafePointer within a closure.
@transparent @transparent
func withUnsafePointer<U>(f: UnsafePointer<T> -> U) -> U { func withUnsafePointer<U>(f: T* -> U) -> U {
let result = f(UnsafePointer<T>(value)) let result = f(UnsafePointer<T>(value))
// Ensure the owner pointer stays alive for the duration of the closure. // Ensure the owner pointer stays alive for the duration of the closure.
_fixLifetime(owner) _fixLifetime(owner)
@@ -247,7 +247,7 @@ func == <T> (lhs: CConstPointer<T>, rhs: CMutablePointer<T>) -> Bool {
/// lvalue), /// lvalue),
/// - an inout argument of Array<T> type for any T, which gets passed as a /// - an inout argument of Array<T> type for any T, which gets passed as a
/// pointer to the beginning of the array, /// pointer to the beginning of the array,
/// - an UnsafePointer<T> for any T or COpaquePointer, which is passed as-is. /// - an T* for any T or COpaquePointer, which is passed as-is.
/// ///
/// The value consists of an owner-value pair. During bridging, a strong /// The value consists of an owner-value pair. During bridging, a strong
/// reference to the owner is held for the duration of the call, and the pointer /// reference to the owner is held for the duration of the call, and the pointer
@@ -293,7 +293,7 @@ struct CMutableVoidPointer : Equatable {
/// Make the pointer available as an UnsafePointer within a closure. /// Make the pointer available as an UnsafePointer within a closure.
@transparent @transparent
func withUnsafePointer<T, U>(f: UnsafePointer<T> -> U) -> U { func withUnsafePointer<T, U>(f: T* -> U) -> U {
let result = f(UnsafePointer(value)) let result = f(UnsafePointer(value))
// Ensure the owner pointer stays alive for the duration of the closure. // Ensure the owner pointer stays alive for the duration of the closure.
_fixLifetime(owner) _fixLifetime(owner)
@@ -314,10 +314,10 @@ func == (lhs: CMutableVoidPointer, rhs: CMutableVoidPointer) -> Bool {
/// - 'nil', which gets passed as a null pointer, /// - 'nil', which gets passed as a null pointer,
/// - an inout argument of the referenced type, which gets passed as a pointer /// - an inout argument of the referenced type, which gets passed as a pointer
/// to a writeback temporary with autoreleasing ownership semantics, /// to a writeback temporary with autoreleasing ownership semantics,
/// - an UnsafePointer<T>, which is passed as-is. /// - an T*, which is passed as-is.
/// ///
/// Unlike CMutablePointer, passing pointers to mutable arrays of ObjC class /// Unlike CMutablePointer, passing pointers to mutable arrays of ObjC class
/// pointers is not directly supported. Unlike UnsafePointer<T>, /// pointers is not directly supported. Unlike T*,
/// ObjCMutablePointer must reference storage that does not own a reference /// ObjCMutablePointer must reference storage that does not own a reference
/// count to the referenced value. UnsafePointer's operations, by contrast, /// count to the referenced value. UnsafePointer's operations, by contrast,
/// assume that the referenced storage owns values loaded from or stored to it. /// assume that the referenced storage owns values loaded from or stored to it.
@@ -363,7 +363,7 @@ struct ObjCMutablePointer<T /* TODO : class */> : Equatable {
@transparent @transparent
func isNull() -> Bool { func isNull() -> Bool {
return UnsafePointer<T>(self).isNull() return (T*(self)).isNull()
} }
/// Access the underlying raw memory, getting and /// Access the underlying raw memory, getting and
@@ -373,7 +373,7 @@ struct ObjCMutablePointer<T /* TODO : class */> : Equatable {
@transparent get { @transparent get {
_debugPrecondition(!isNull()) _debugPrecondition(!isNull())
// We can do a strong load normally. // We can do a strong load normally.
return UnsafePointer<T>(self).pointee return (T*(self)).pointee
} }
/// Set the value the pointer points to, copying over the previous value. /// Set the value the pointer points to, copying over the previous value.
/// ///
@@ -446,7 +446,7 @@ struct CConstPointer<T> : Equatable {
/// Make the pointer available as an UnsafePointer within a closure. /// Make the pointer available as an UnsafePointer within a closure.
@transparent @transparent
func withUnsafePointer<U>(f: UnsafePointer<T> -> U) -> U { func withUnsafePointer<U>(f: T* -> U) -> U {
let result = f(UnsafePointer<T>(value)) let result = f(UnsafePointer<T>(value))
// Ensure the owner pointer stays alive for the duration of the closure. // Ensure the owner pointer stays alive for the duration of the closure.
_fixLifetime(owner) _fixLifetime(owner)
@@ -488,7 +488,7 @@ struct CConstVoidPointer : Equatable {
/// Make the pointer available as an UnsafePointer within a closure. /// Make the pointer available as an UnsafePointer within a closure.
@transparent @transparent
func withUnsafePointer<T, U>(f: UnsafePointer<T> -> U) -> U { func withUnsafePointer<T, U>(f: T* -> U) -> U {
let result = f(UnsafePointer(value)) let result = f(UnsafePointer(value))
// Ensure the owner pointer stays alive for the duration of the closure. // Ensure the owner pointer stays alive for the duration of the closure.
_fixLifetime(owner) _fixLifetime(owner)
@@ -550,7 +550,7 @@ extension COpaquePointer {
@transparent @transparent
func _convertCConstPointerToUnsafePointer<T>(p: CConstPointer<T>) func _convertCConstPointerToUnsafePointer<T>(p: CConstPointer<T>)
-> UnsafePointer<T> { -> T* {
return UnsafePointer(p.value) return UnsafePointer(p.value)
} }
@@ -562,7 +562,7 @@ func _convertCConstVoidPointerToCOpaquePointer(p: CConstVoidPointer)
@transparent @transparent
func _convertCMutablePointerToUnsafePointer<T>(p: CMutablePointer<T>) func _convertCMutablePointerToUnsafePointer<T>(p: CMutablePointer<T>)
-> UnsafePointer<T> { -> T* {
return UnsafePointer(p.value) return UnsafePointer(p.value)
} }
@@ -574,7 +574,7 @@ func _convertCMutableVoidPointerToCOpaquePointer(p: CMutableVoidPointer)
@transparent @transparent
func _convertObjCMutablePointerToUnsafePointer<T>(p: ObjCMutablePointer<T>) func _convertObjCMutablePointerToUnsafePointer<T>(p: ObjCMutablePointer<T>)
-> UnsafePointer<T> { -> T* {
return UnsafePointer(p.value) return UnsafePointer(p.value)
} }
@@ -588,7 +588,7 @@ func _convertObjCMutablePointerToUnsafePointer<T>(p: ObjCMutablePointer<T>)
// the arguments to C*Pointer types with nil owner references. // the arguments to C*Pointer types with nil owner references.
@transparent @transparent
func _convertUnsafePointerToCConstPointer<T>(p: UnsafePointer<T>) func _convertUnsafePointerToCConstPointer<T>(p: T*)
-> CConstPointer<T> { -> CConstPointer<T> {
return CConstPointer(_nilNativeObject, p.value) return CConstPointer(_nilNativeObject, p.value)
} }
@@ -600,7 +600,7 @@ func _convertCOpaquePointerToCConstVoidPointer(p: COpaquePointer)
} }
@transparent @transparent
func _convertUnsafePointerToCMutablePointer<T>(p: UnsafePointer<T>) func _convertUnsafePointerToCMutablePointer<T>(p: T*)
-> CMutablePointer<T> { -> CMutablePointer<T> {
return CMutablePointer(owner: _nilNativeObject, value: p.value) return CMutablePointer(owner: _nilNativeObject, value: p.value)
} }
@@ -612,7 +612,7 @@ func _convertCOpaquePointerToCMutableVoidPointer(p: COpaquePointer)
} }
@transparent @transparent
func _convertUnsafePointerToObjCMutablePointer<T>(p: UnsafePointer<T>) func _convertUnsafePointerToObjCMutablePointer<T>(p: T*)
-> ObjCMutablePointer<T> { -> ObjCMutablePointer<T> {
return ObjCMutablePointer(p.value) return ObjCMutablePointer(p.value)
} }

View File

@@ -111,7 +111,7 @@ extension COpaquePointer {
// FIXME: This shouldn't have to be in an extension. // FIXME: This shouldn't have to be in an extension.
// //
/// Convert a typed UnsafePointer to an opaque C pointer. /// Convert a typed UnsafePointer to an opaque C pointer.
init<T>(_ from : UnsafePointer<T>) { init<T>(_ from : T*) {
value = from.value; value = from.value;
} }
} }

View File

@@ -63,13 +63,13 @@ struct ContiguousArrayBuffer<T> : ArrayBufferType, LogicValue {
/// If the elements are stored contiguously, a pointer to the first /// If the elements are stored contiguously, a pointer to the first
/// element. Otherwise, nil. /// element. Otherwise, nil.
var elementStorage: UnsafePointer<T> { var elementStorage: T* {
return base ? base.elementStorage : nil return base ? base.elementStorage : nil
} }
/// A pointer to the first element, assuming that the elements are stored /// A pointer to the first element, assuming that the elements are stored
/// contiguously. /// contiguously.
var _unsafeElementStorage: UnsafePointer<T> { var _unsafeElementStorage: T* {
return base.elementStorage return base.elementStorage
} }
@@ -165,8 +165,8 @@ struct ContiguousArrayBuffer<T> : ArrayBufferType, LogicValue {
/// starting at target. Return a pointer past-the-end of the /// starting at target. Return a pointer past-the-end of the
/// just-initialized memory. /// just-initialized memory.
func _uninitializedCopy( func _uninitializedCopy(
subRange: Range<Int>, target: UnsafePointer<T> subRange: Range<Int>, target: T*
) -> UnsafePointer<T> { ) -> T* {
_sanityCheck(subRange.startIndex >= 0) _sanityCheck(subRange.startIndex >= 0)
_sanityCheck(subRange.endIndex >= subRange.startIndex) _sanityCheck(subRange.endIndex >= subRange.startIndex)
_sanityCheck(subRange.endIndex <= count) _sanityCheck(subRange.endIndex <= count)

View File

@@ -195,7 +195,7 @@ protocol Mirror {
/// without unnecessary copying of the underlying value. /// without unnecessary copying of the underlying value.
@asmname("swift_unsafeReflectAny") func unsafeReflect<T>( @asmname("swift_unsafeReflectAny") func unsafeReflect<T>(
owner: Builtin.NativeObject, owner: Builtin.NativeObject,
ptr: UnsafePointer<T> ptr: T*
) -> Mirror ) -> Mirror

View File

@@ -18,7 +18,7 @@ struct SliceBuffer<T> : ArrayBufferType {
init( init(
owner: AnyObject?, owner: AnyObject?,
start: UnsafePointer<T>, start: T*,
count: Int, count: Int,
hasNativeBuffer: Bool hasNativeBuffer: Bool
) { ) {
@@ -73,7 +73,7 @@ struct SliceBuffer<T> : ArrayBufferType {
/// An object that keeps the elements stored in this buffer alive /// An object that keeps the elements stored in this buffer alive
var owner: AnyObject? var owner: AnyObject?
var start: UnsafePointer<T> var start: T*
var _countAndFlags: UInt var _countAndFlags: UInt
//===--- Non-essential bits ---------------------------------------------===// //===--- Non-essential bits ---------------------------------------------===//
@@ -111,8 +111,8 @@ struct SliceBuffer<T> : ArrayBufferType {
} }
func _uninitializedCopy( func _uninitializedCopy(
subRange: Range<Int>, var target: UnsafePointer<T> subRange: Range<Int>, var target: T*
) -> UnsafePointer<T> { ) -> T* {
_invariantCheck() _invariantCheck()
_sanityCheck(subRange.startIndex >= 0) _sanityCheck(subRange.startIndex >= 0)
_sanityCheck(subRange.endIndex >= subRange.startIndex) _sanityCheck(subRange.endIndex >= subRange.startIndex)
@@ -123,7 +123,7 @@ struct SliceBuffer<T> : ArrayBufferType {
return target return target
} }
var elementStorage: UnsafePointer<T> { var elementStorage: T* {
return start return start
} }

View File

@@ -240,7 +240,7 @@ extension UTF16 {
} }
static func copy<T: StringElement, U: StringElement>( static func copy<T: StringElement, U: StringElement>(
source: UnsafePointer<T>, destination: UnsafePointer<U>, count: Int source: T*, destination: UnsafePointer<U>, count: Int
) { ) {
if UWord(Builtin.strideof(T.self)) == UWord(Builtin.strideof(U.self)) { if UWord(Builtin.strideof(T.self)) == UWord(Builtin.strideof(U.self)) {
c_memcpy( c_memcpy(

View File

@@ -32,7 +32,7 @@ struct UnsafeArray<T> : Collection, Generator {
return (_position + i).pointee return (_position + i).pointee
} }
init(start: UnsafePointer<T>, length: Int) { init(start: T*, length: Int) {
_position = start _position = start
_end = start + length _end = start + length
} }
@@ -48,5 +48,5 @@ struct UnsafeArray<T> : Collection, Generator {
return self return self
} }
var _position, _end: UnsafePointer<T> var _position, _end: T*
} }

View File

@@ -285,34 +285,34 @@ struct UnsafePointer<T> : BidirectionalIndex, Comparable, Hashable {
} }
@transparent @transparent
func == <T> (lhs: UnsafePointer<T>, rhs: UnsafePointer<T>) -> Bool { func == <T> (lhs: T*, rhs: T*) -> Bool {
return Bool(Builtin.cmp_eq_RawPointer(lhs.value, rhs.value)) return Bool(Builtin.cmp_eq_RawPointer(lhs.value, rhs.value))
} }
@transparent @transparent
func < <T>(lhs: UnsafePointer<T>, rhs: UnsafePointer<T>) -> Bool { func < <T>(lhs: T*, rhs: T*) -> Bool {
return Bool(Builtin.cmp_ult_RawPointer(lhs.value, rhs.value)) return Bool(Builtin.cmp_ult_RawPointer(lhs.value, rhs.value))
} }
@transparent @transparent
func + <T>(lhs: UnsafePointer<T>, rhs: Int) -> UnsafePointer<T> { func + <T>(lhs: T*, rhs: Int) -> T* {
return UnsafePointer( return UnsafePointer(
Builtin.gep_Word(lhs.value, (rhs * Int(Builtin.strideof(T.self))).value)) Builtin.gep_Word(lhs.value, (rhs * Int(Builtin.strideof(T.self))).value))
} }
@transparent @transparent
func + <T>(lhs: Int, func + <T>(lhs: Int,
rhs: UnsafePointer<T>) -> UnsafePointer<T> { rhs: T*) -> T* {
return rhs + lhs return rhs + lhs
} }
@transparent @transparent
func - <T>(lhs: UnsafePointer<T>, rhs: Int) -> UnsafePointer<T> { func - <T>(lhs: T*, rhs: Int) -> T* {
return lhs + -rhs return lhs + -rhs
} }
@transparent @transparent
func - <T>(lhs: UnsafePointer<T>, rhs: UnsafePointer<T>) -> Int { func - <T>(lhs: T*, rhs: T*) -> Int {
return return
Int(Builtin.sub_Word(Builtin.ptrtoint_Word(lhs.value), Int(Builtin.sub_Word(Builtin.ptrtoint_Word(lhs.value),
Builtin.ptrtoint_Word(rhs.value))) Builtin.ptrtoint_Word(rhs.value)))
@@ -320,12 +320,12 @@ func - <T>(lhs: UnsafePointer<T>, rhs: UnsafePointer<T>) -> Int {
} }
@transparent @transparent
@assignment func += <T>(inout lhs: UnsafePointer<T>, rhs: Int) { @assignment func += <T>(inout lhs: T*, rhs: Int) {
lhs = lhs + rhs lhs = lhs + rhs
} }
@transparent @transparent
@assignment func -= <T>(inout lhs: UnsafePointer<T>, rhs: Int) { @assignment func -= <T>(inout lhs: T*, rhs: Int) {
lhs = lhs - rhs lhs = lhs - rhs
} }
@@ -345,7 +345,7 @@ struct RawByte {
// Make nil work with UnsafePointer // Make nil work with UnsafePointer
extension _Nil { extension _Nil {
@transparent @transparent
@conversion func __conversion<T>() -> UnsafePointer<T> { @conversion func __conversion<T>() -> T* {
return .null() return .null()
} }
} }

View File

@@ -143,7 +143,7 @@ func __swift_initializeCocoaStringBridge() -> COpaquePointer {
// buffer copying. // buffer copying.
// //
func _cocoaStringReadAllImpl( func _cocoaStringReadAllImpl(
source: _CocoaString, destination: UnsafePointer<UTF16.CodeUnit>) { source: _CocoaString, destination: UTF16.CodeUnit*) {
let cfSelf: CFString = reinterpretCast(source) let cfSelf: CFString = reinterpretCast(source)
CFStringGetCharacters( CFStringGetCharacters(
cfSelf, CFRange(location: 0, length: CFStringGetLength(cfSelf)), destination) cfSelf, CFRange(location: 0, length: CFStringGetLength(cfSelf)), destination)
@@ -239,7 +239,7 @@ class _NSContiguousString : NSString {
} }
@objc @objc
func _fastCharacterContents() -> UnsafePointer<unichar> { func _fastCharacterContents() -> unichar* {
return value.elementWidth == 2 ? UnsafePointer(value.startUTF16) : nil return value.elementWidth == 2 ? UnsafePointer(value.startUTF16) : nil
} }