上一页 1 2 3 4 5 6 7 ··· 30 下一页

2019年3月22日

摘要: 只看 Swift Array 到 NSArrayArray 里的源代码extension Array { @inlinable public // @SPI(Foundation) func _bridgeToObjectiveCImpl() -> AnyObject { return _buffer._asCocoaArray() }}这里看到,调用了_asCocoaArray ... 阅读全文
posted @ 2019-03-22 00:48 花老🐯 阅读(634) 评论(0) 推荐(0) 编辑

2019年3月20日

摘要: 判断是否为空使用的是Collection协议里isEmpty的判断。 public var isEmpty: Bool { return startIndex == endIndex }startIndex 总是返回 0。 public var startIndex: Int { return 0 }endIndex代码如下: @inlinable public va... 阅读全文
posted @ 2019-03-20 22:57 花老🐯 阅读(129) 评论(0) 推荐(0) 编辑
摘要: init() 函数在 Array 里 public init() { _buffer = _Buffer() }以Buffer 是 _ContiguousArrayBuffer 为例。即初始化了一个_ContiguousArrayBuffer。在_ContiguousArrayBuffer里 /// Create an empty buffer. @inlinable intern... 阅读全文
posted @ 2019-03-20 22:33 花老🐯 阅读(479) 评论(0) 推荐(0) 编辑
摘要: public struct Array: _DestructorSafeContainer { #if _runtime(_ObjC) @usableFromInline internal typealias _Buffer = _ArrayBuffer #else @usableFromInline internal typealias _Buffer = _ContiguousAr... 阅读全文
posted @ 2019-03-20 22:02 花老🐯 阅读(608) 评论(0) 推荐(0) 编辑
摘要: to OC func _bridgeToObjectiveCImpl() -> AnyObject { if _guts.isSmall { return _guts.asSmall.withUTF8 { bufPtr in // TODO(String bridging): worth isASCII check for different encoding? ... 阅读全文
posted @ 2019-03-20 20:09 花老🐯 阅读(508) 评论(0) 推荐(0) 编辑
摘要: 以append操作为例 public mutating func append(_ other: String) { if self.isEmpty && !_guts.hasNativeStorage { self = other return } self._guts.append(other._guts) }_StringGuts 做了实际的工作... 阅读全文
posted @ 2019-03-20 08:56 花老🐯 阅读(233) 评论(0) 推荐(0) 编辑
摘要: 即以 UTF16 编码的格式来查看字符串。 UTF16View 是一个结构体 @_fixed_layout public struct UTF16View { @usableFromInline internal var _guts: _StringGuts @inlinable internal init(_ guts: _StringGuts) { se... 阅读全文
posted @ 2019-03-20 08:29 花老🐯 阅读(174) 评论(0) 推荐(0) 编辑
摘要: 即以 Unicode Scarlar 的方式来查看字符串。 /// let flag = "🇵🇷" /// for v in flag.unicodeScalars { /// print(v.value) /// } /// // 127477 /// // 127479UnicodeScalarView 是一个结构体e... 阅读全文
posted @ 2019-03-20 08:25 花老🐯 阅读(339) 评论(0) 推荐(0) 编辑
摘要: 在 String 里,用来索引 Character 的,不是整数,而是StringIndex 内部结构extension String { /// A position of a character or code unit in a string. @_fixed_layout public struct Index { @usableFromInline internal ... 阅读全文
posted @ 2019-03-20 08:02 花老🐯 阅读(646) 评论(0) 推荐(0) 编辑
摘要: Native strings have tail-allocated storage, which begins at an offset of nativeBias from the storage object's address. String literals, which reside in the constant section, are encoded as their start... 阅读全文
posted @ 2019-03-20 07:57 花老🐯 阅读(187) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 30 下一页

导航