From 4baeb6ce14a97371f5602b8474aa27a5389a9a9f Mon Sep 17 00:00:00 2001 From: L1MeN9Yu Date: Wed, 5 Jan 2022 10:03:50 +0800 Subject: [PATCH] [LevelDB] : Cache make public --- Sources/LMDB/Version/Version.swift | 20 +++++--------------- Sources/LevelDB/Cache.swift | 2 +- Sources/LevelDB/Database.swift | 6 +++--- Sources/LevelDB/WriteBatch.swift | 2 +- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Sources/LMDB/Version/Version.swift b/Sources/LMDB/Version/Version.swift index c012308..b133fef 100644 --- a/Sources/LMDB/Version/Version.swift +++ b/Sources/LMDB/Version/Version.swift @@ -8,23 +8,13 @@ public enum Version {} public extension Version { - static let string = { - "\(major).\(minor).\(patch)" - }() + static let string = "\(major).\(minor).\(patch)" - static let major = { - MDB_VERSION_MAJOR - }() + static let major = MDB_VERSION_MAJOR - static let minor = { - MDB_VERSION_MINOR - }() + static let minor = MDB_VERSION_MINOR - static let patch = { - MDB_VERSION_PATCH - }() + static let patch = MDB_VERSION_PATCH - static let date = { - MDB_VERSION_DATE - }() + static let date = MDB_VERSION_DATE } diff --git a/Sources/LevelDB/Cache.swift b/Sources/LevelDB/Cache.swift index 29d9d0c..a102505 100644 --- a/Sources/LevelDB/Cache.swift +++ b/Sources/LevelDB/Cache.swift @@ -7,7 +7,7 @@ public class Cache { let pointer: OpaquePointer - init(type: Type) { + public init(type: Type) { switch type { case .lru(let capacity): pointer = leveldb_cache_create_lru(capacity) diff --git a/Sources/LevelDB/Database.swift b/Sources/LevelDB/Database.swift index b3ff818..ab2f545 100644 --- a/Sources/LevelDB/Database.swift +++ b/Sources/LevelDB/Database.swift @@ -41,7 +41,7 @@ public class Database { public extension Database { func put(key: String, value: Value) throws { let valueData = try value.toData() - try valueData.toData().withUnsafeBytes { (rawBufferPointer: UnsafeRawBufferPointer) -> Void in + try valueData.toData().withUnsafeBytes { (rawBufferPointer: UnsafeRawBufferPointer) in let unsafeBufferPointer = rawBufferPointer.bindMemory(to: Int8.self) guard let unsafePointer = unsafeBufferPointer.baseAddress else { throw LevelDBError.put(message: nil) @@ -58,7 +58,7 @@ public extension Database { } func get(key: String) throws -> Value? { - var valueLength: Int = 0 + var valueLength = 0 var errorPointer: UnsafeMutablePointer? guard let dataPointer = leveldb_get(pointer, readOption.pointer, key, key.utf8.count, &valueLength, &errorPointer) else { if let error = errorPointer { @@ -131,7 +131,7 @@ public extension Database { let keyData = Data(bytes: keyPointer, count: keyLength) let value = Data(bytes: valuePointer, count: valueLength) if let key = String(data: keyData, encoding: .utf8) { - var stop: Bool = false + var stop = false action(key, value, &stop) if stop { break } diff --git a/Sources/LevelDB/WriteBatch.swift b/Sources/LevelDB/WriteBatch.swift index 9ecf3a6..2e0711d 100644 --- a/Sources/LevelDB/WriteBatch.swift +++ b/Sources/LevelDB/WriteBatch.swift @@ -24,7 +24,7 @@ public class WriteBatch { public extension WriteBatch { func put(key: String, value: Value) throws { let valueData = try value.toData() - try valueData.withUnsafeBytes { (rawBufferPointer: UnsafeRawBufferPointer) -> Void in + try valueData.withUnsafeBytes { (rawBufferPointer: UnsafeRawBufferPointer) in let unsafeBufferPointer = rawBufferPointer.bindMemory(to: Int8.self) guard let unsafePointer = unsafeBufferPointer.baseAddress else { throw LevelDBError.put(message: nil)