//===----------------------------------------------------------------------===// // // This source file is part of the Swift.org open source project // // Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors // Licensed under Apache License v2.0 with Runtime Library Exception // // See http://swift.org/LICENSE.txt for license information // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors // //===----------------------------------------------------------------------===// // Pre-specialization of some popular generic classes and functions. //===----------------------------------------------------------------------===// import Swift struct _Prespecialize { class C {} // Create specializations for the arrays of most // popular builtin integer and floating point types. static internal func _specializeArrays() { func _createArrayUser(sampleValue: Element) { // Initializers. let _: [Element] = [ sampleValue ] var a = [Element](repeating: sampleValue, count: 1) // Read array element let _ = 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 let _ = 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 UnicodeScalar) _createArrayUserWithoutSorting("a".utf8) _createArrayUserWithoutSorting("a".utf16) _createArrayUserWithoutSorting("a".unicodeScalars) _createArrayUserWithoutSorting("a".characters) } // Force pre-specialization of Range static internal func _specializeRanges() -> Int { let a = [Int](repeating: 1, count: 10) var count = 0 // Specialize Range for integers for i in 0..