Skip to content

Commit

Permalink
[LevelDB] : Cache make public
Browse files Browse the repository at this point in the history
  • Loading branch information
L1MeN9Yu committed Jan 5, 2022
1 parent e3c21e4 commit 4baeb6c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
20 changes: 5 additions & 15 deletions Sources/LMDB/Version/Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion Sources/LevelDB/Cache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions Sources/LevelDB/Database.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Database {
public extension Database {
func put<Value: DataEncodable>(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)
Expand All @@ -58,7 +58,7 @@ public extension Database {
}

func get<Value: DataDecodable>(key: String) throws -> Value? {
var valueLength: Int = 0
var valueLength = 0
var errorPointer: UnsafeMutablePointer<Int8>?
guard let dataPointer = leveldb_get(pointer, readOption.pointer, key, key.utf8.count, &valueLength, &errorPointer) else {
if let error = errorPointer {
Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion Sources/LevelDB/WriteBatch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class WriteBatch {
public extension WriteBatch {
func put<Value: DataEncodable>(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)
Expand Down

0 comments on commit 4baeb6c

Please sign in to comment.