From c4232128afb52f4673cbca10d118a8aa6c9e1989 Mon Sep 17 00:00:00 2001 From: darquro Date: Sat, 10 Mar 2018 00:15:16 +0900 Subject: [PATCH 1/3] [stdlib] Fast-path ad-hoc printing of Strings --- stdlib/public/core/OutputStream.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stdlib/public/core/OutputStream.swift b/stdlib/public/core/OutputStream.swift index 9b4fea7eee8f4..83ef632630e53 100644 --- a/stdlib/public/core/OutputStream.swift +++ b/stdlib/public/core/OutputStream.swift @@ -380,6 +380,11 @@ internal func _adHocPrint_unlocked( internal func _print_unlocked( _ value: T, _ target: inout TargetStream ) { + if let string = value as? String { + let mirror = Mirror(reflecting: string) + _adHocPrint_unlocked(string, mirror, &target, isDebugPrint: false) + return + } // Optional has no representation suitable for display; therefore, // values of optional type should be printed as a debug // string. Check for Optional first, before checking protocol From 149e91ec849922350723e95d47d4d3e6ae7b47b5 Mon Sep 17 00:00:00 2001 From: darquro Date: Sat, 10 Mar 2018 02:12:36 +0900 Subject: [PATCH 2/3] [stdlib] fix _adHocPrint to TextOutputStream's write. (#15108) --- stdlib/public/core/OutputStream.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stdlib/public/core/OutputStream.swift b/stdlib/public/core/OutputStream.swift index 83ef632630e53..db967fab52060 100644 --- a/stdlib/public/core/OutputStream.swift +++ b/stdlib/public/core/OutputStream.swift @@ -381,8 +381,7 @@ internal func _print_unlocked( _ value: T, _ target: inout TargetStream ) { if let string = value as? String { - let mirror = Mirror(reflecting: string) - _adHocPrint_unlocked(string, mirror, &target, isDebugPrint: false) + target.write(string) return } // Optional has no representation suitable for display; therefore, From a77336a640309d7306a1f91bf65495b27beb2f0c Mon Sep 17 00:00:00 2001 From: darquro Date: Sat, 10 Mar 2018 03:11:32 +0900 Subject: [PATCH 3/3] [stdlib] move the string check after the optional check below it. (#15108) --- stdlib/public/core/OutputStream.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stdlib/public/core/OutputStream.swift b/stdlib/public/core/OutputStream.swift index db967fab52060..01d07313c7a6f 100644 --- a/stdlib/public/core/OutputStream.swift +++ b/stdlib/public/core/OutputStream.swift @@ -380,10 +380,6 @@ internal func _adHocPrint_unlocked( internal func _print_unlocked( _ value: T, _ target: inout TargetStream ) { - if let string = value as? String { - target.write(string) - return - } // Optional has no representation suitable for display; therefore, // values of optional type should be printed as a debug // string. Check for Optional first, before checking protocol @@ -394,6 +390,12 @@ internal func _print_unlocked( debugPrintable.debugDescription.write(to: &target) return } + + if let string = value as? String { + target.write(string) + return + } + if case let streamableObject as TextOutputStreamable = value { streamableObject.write(to: &target) return