根据下标取值
关键代码如下:
func _getElement(
_ index: Int,
wasNativeTypeChecked: Bool,
matchingSubscriptCheck: _DependenceToken
) -> Element {
#if _runtime(_ObjC)
return _buffer.getElement(index, wasNativeTypeChecked: wasNativeTypeChecked)
#else
return _buffer.getElement(index)
#endif
}
_ContiguousArrayBuffer 里的代码如下,只是取了一个指针的偏移。
internal func getElement(_ i: Int) -> Element {
_internalInvariant(i >= 0 && i < count, "Array index out of range")
return firstElementAddress[i]
}
|
请发表评论