Skip to content

Commit

Permalink
Drop some more Swift 4.1 specific things.
Browse files Browse the repository at this point in the history
Progress on #1210
  • Loading branch information
thomasvl committed Apr 7, 2022
1 parent c9b8d33 commit f8c427b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 24 deletions.
15 changes: 1 addition & 14 deletions Sources/SwiftProtobuf/NameMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,17 @@ fileprivate class InternPool {
private var interned = [UnsafeRawBufferPointer]()

func intern(utf8: String.UTF8View) -> UnsafeRawBufferPointer {
#if swift(>=4.1)
let mutable = UnsafeMutableRawBufferPointer.allocate(byteCount: utf8.count,
alignment: MemoryLayout<UInt8>.alignment)
#else
let mutable = UnsafeMutableRawBufferPointer.allocate(count: utf8.count)
#endif
mutable.copyBytes(from: utf8)
let immutable = UnsafeRawBufferPointer(mutable)
interned.append(immutable)
return immutable
}

func intern(utf8Ptr: UnsafeBufferPointer<UInt8>) -> UnsafeRawBufferPointer {
#if swift(>=4.1)
let mutable = UnsafeMutableRawBufferPointer.allocate(byteCount: utf8Ptr.count,
alignment: MemoryLayout<UInt8>.alignment)
#else
let mutable = UnsafeMutableRawBufferPointer.allocate(count: utf8.count)
#endif
mutable.copyBytes(from: utf8Ptr)
let immutable = UnsafeRawBufferPointer(mutable)
interned.append(immutable)
Expand All @@ -70,12 +62,7 @@ fileprivate class InternPool {

deinit {
for buff in interned {
#if swift(>=4.1)
buff.deallocate()
#else
let p = UnsafeMutableRawPointer(mutating: buff.baseAddress)!
p.deallocate(bytes: buff.count, alignedTo: 1)
#endif
buff.deallocate()
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions Tests/SwiftProtobufTests/Test_JSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,6 @@ class Test_JSON: XCTestCase, PBTestHelpers {
}

func testOptionalString_controlCharacters() {
// This is known to fail on Swift Linux 4.1 and earlier,
// so skip it there.
// See https://bugs.swift.org/browse/SR-4218 for details.
#if !os(Linux) || swift(>=4.2)
// Verify that all C0 controls are correctly escaped
assertJSONEncode("{\"optionalString\":\"\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\"}") {(o: inout MessageTestType) in
o.optionalString = "\u{00}\u{01}\u{02}\u{03}\u{04}\u{05}\u{06}\u{07}"
Expand All @@ -672,7 +668,6 @@ class Test_JSON: XCTestCase, PBTestHelpers {
assertJSONEncode("{\"optionalString\":\"\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001F\"}") {(o: inout MessageTestType) in
o.optionalString = "\u{18}\u{19}\u{1a}\u{1b}\u{1c}\u{1d}\u{1e}\u{1f}"
}
#endif
}

func testOptionalBytes() throws {
Expand Down
5 changes: 0 additions & 5 deletions Tests/SwiftProtobufTests/Test_TextFormat_proto3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,6 @@ class Test_TextFormat_proto3: XCTestCase, PBTestHelpers {
}

func testEncoding_optionalString_controlCharacters() throws {
// This is known to fail on Swift Linux 4.1 and earlier,
// so skip it there.
// See https://bugs.swift.org/browse/SR-4218 for details.
#if !os(Linux) || swift(>=4.2)
assertTextFormatEncode("optional_string: \"\\001\\002\\003\\004\\005\\006\\007\"\n") {
(o: inout MessageTestType) in
o.optionalString = "\u{01}\u{02}\u{03}\u{04}\u{05}\u{06}\u{07}"
Expand All @@ -675,7 +671,6 @@ class Test_TextFormat_proto3: XCTestCase, PBTestHelpers {
(o: inout MessageTestType) in
o.optionalString = "\u{18}\u{19}\u{1a}\u{1b}\u{1c}\u{1d}\u{1e}\u{1f}"
}
#endif
}

func testEncoding_optionalString_UTF8() throws {
Expand Down

0 comments on commit f8c427b

Please sign in to comment.