Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions stdlib/public/core/StringStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ extension _AbstractStringStorage {
fallthrough
case (_cocoaUTF8Encoding, _):
guard maxLength >= count + 1 else { return 0 }
let buffer =
UnsafeMutableBufferPointer(start: outputPtr, count: maxLength)
buffer.initialize(from: UnsafeBufferPointer(start: start, count: count))
let buffer = UnsafeMutableBufferPointer(start: outputPtr, count: maxLength)
_ = buffer.initialize(from: UnsafeBufferPointer(start: start, count: count))
Copy link
Contributor

@Azoy Azoy Dec 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @milseman @Catfish-Man can this be rewritten as:

guard maxLength >= count + 1 else { return 0 }
outputPtr.initialize(from: start, count: count)
outputPtr[count] = 0
return 1

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly suspect it can! Good catch

buffer[count] = 0
return 1
default:
Expand Down