mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Instead of inlining a series of string comparisons, we call a library function which does the string lookup on a table of static strings. This reduces the code size of those initializers dramatically. Performance wise it's slower than before, because the string comparisons are not inlined anymore.
36 lines
1.2 KiB
Swift
36 lines
1.2 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// This file contains compiler intrinsics for optimized string switch
|
|
// implementations. All functions and types declared in this file are not
|
|
// intended to be used by switch source directly.
|
|
|
|
/// The compiler intrinsic which is called to lookup a string in a table
|
|
/// of static string case values.
|
|
@_semantics("stdlib_binary_only")
|
|
@_semantics("findStringSwitchCase")
|
|
public // COMPILER_INTRINSIC
|
|
func _findStringSwitchCase(
|
|
cases: [StaticString],
|
|
string: String) -> Int {
|
|
|
|
for (idx, s) in cases.enumerated() {
|
|
if String(_builtinStringLiteral: s.utf8Start._rawValue,
|
|
utf8CodeUnitCount: s._utf8CodeUnitCount,
|
|
isASCII: s.isASCII._value) == string {
|
|
return idx
|
|
}
|
|
}
|
|
return -1
|
|
}
|
|
|