//===----------------------------------------------------------------------===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See https://swift.org/LICENSE.txt for license information // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // //===----------------------------------------------------------------------===// // Pre-specialization of some popular generic classes and functions. //===----------------------------------------------------------------------===// import Swift @_frozen // FIXME(sil-serialize-all) @usableFromInline // FIXME(sil-serialize-all) internal enum _Prespecialize { // Create specializations for the arrays of most // popular builtin integer and floating point types. internal static func _specializeArrays() { func _createArrayUser(_ sampleValue: Element) { // Initializers. let _: [Element] = [sampleValue] var a = [Element](repeating: sampleValue, count: 1) // Read array element _ = a[0] // Set array elements for j in 1.. print(sampleValue) print("Element:\(sampleValue)") } func _createArrayUserWithoutSorting(_ sampleValue: Element) { // Initializers. let _: [Element] = [sampleValue] var a = [Element](repeating: sampleValue, count: 1) // Read array element _ = a[0] // Set array elements for j in 0.. print(sampleValue) print("Element:\(sampleValue)") } // Force pre-specialization of arrays with elements of different // integer types. _createArrayUser(1 as Int) _createArrayUser(1 as Int8) _createArrayUser(1 as Int16) _createArrayUser(1 as Int32) _createArrayUser(1 as Int64) _createArrayUser(1 as UInt) _createArrayUser(1 as UInt8) _createArrayUser(1 as UInt16) _createArrayUser(1 as UInt32) _createArrayUser(1 as UInt64) // Force pre-specialization of arrays with elements of different // floating point types. _createArrayUser(1.5 as Float) _createArrayUser(1.5 as Double) // Force pre-specialization of string arrays _createArrayUser("a" as String) // Force pre-specialization of arrays with elements of different // character and unicode scalar types. _createArrayUser("a" as Character) _createArrayUser("a" as Unicode.Scalar) _createArrayUserWithoutSorting("a".utf8) _createArrayUserWithoutSorting("a".utf16) _createArrayUserWithoutSorting("a".unicodeScalars) _createArrayUserWithoutSorting("a") } // Force pre-specialization of Range @discardableResult internal static func _specializeRanges() -> Int { let a = [Int](repeating: 1, count: 10) var count = 0 // Specialize Range for integers for i in 0..