Skip to content

Commit 06e55e7

Browse files
committed
Simplify
1 parent bf021c5 commit 06e55e7

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

Sources/SQLite/Core/Blob.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,7 @@ public final class Blob {
4040
self.init(data: NSData())
4141
return
4242
}
43-
let buffer = UnsafeMutablePointer<UInt8>.allocate(capacity: bytes.count)
44-
for idx in 0..<bytes.count {
45-
buffer.advanced(by: idx).pointee = bytes[idx]
46-
}
47-
48-
let data = NSData(
49-
bytesNoCopy: UnsafeMutableRawPointer(buffer),
50-
length: bytes.count,
51-
freeWhenDone: true
52-
)
53-
self.init(data: data)
43+
self.init(data: NSData(bytes: bytes, length: bytes.count))
5444
}
5545

5646
public convenience init(bytes: UnsafeRawPointer, length: Int) {

Tests/SQLiteTests/Core/BlobTests.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ class BlobTests: XCTestCase {
1313
XCTAssertEqual(blob.toHex(), "")
1414
}
1515

16+
func test_description() {
17+
let blob = Blob(bytes: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 150, 250, 255])
18+
XCTAssertEqual(blob.description, "x'000a141e28323c46505a6496faff'")
19+
}
20+
21+
func test_description_empty() {
22+
let blob = Blob(bytes: [])
23+
XCTAssertEqual(blob.description, "x''")
24+
}
25+
1626
func test_init_array() {
17-
let blob = Blob(bytes: [42, 42, 42])
18-
XCTAssertEqual([UInt8](blob.data), [42, 42, 42])
27+
let blob = Blob(bytes: [42, 43, 44])
28+
XCTAssertEqual([UInt8](blob.data), [42, 43, 44])
1929
}
2030

2131
func test_init_unsafeRawPointer() {

0 commit comments

Comments
 (0)