Skip to content
Open

ARC #42

Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions Classes/LDBSnapshot.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ @interface LDBSnapshot () {
@implementation LDBSnapshot

+ (LDBSnapshot *) snapshotFromDB:(LevelDB *)database {
LDBSnapshot *snapshot = [[[LDBSnapshot alloc] init] autorelease];
LDBSnapshot *snapshot = [[LDBSnapshot alloc] init];
snapshot->_snapshot = [database db]->GetSnapshot();
snapshot->_db = database;
return snapshot;
Expand Down Expand Up @@ -84,14 +84,14 @@ - (id) valueForKey:(NSString *)key {
}

- (NSArray *)allKeys {
NSMutableArray *keys = [[[NSMutableArray alloc] init] autorelease];
NSMutableArray *keys = [[NSMutableArray alloc] init];
[self enumerateKeysUsingBlock:^(LevelDBKey *key, BOOL *stop) {
[keys addObject:NSDataFromLevelDBKey(key)];
}];
return [NSArray arrayWithArray:keys];
}
- (NSArray *)keysByFilteringWithPredicate:(NSPredicate *)predicate {
NSMutableArray *keys = [[[NSMutableArray alloc] init] autorelease];
NSMutableArray *keys = [[NSMutableArray alloc] init];
[self enumerateKeysBackward:NO
startingAtKey:nil
filteredByPredicate:predicate
Expand Down Expand Up @@ -170,7 +170,6 @@ - (void) close {
}
- (void) dealloc {
[self close];
[super dealloc];
}

@end
8 changes: 2 additions & 6 deletions Classes/LDBWriteBatch.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

@interface LDBWritebatch () {
leveldb::WriteBatch _writeBatch;
id _db;
}

@property (readonly) leveldb::WriteBatch writeBatch;
Expand All @@ -28,8 +27,8 @@ @implementation LDBWritebatch {
@synthesize db = _db;

+ (instancetype) writeBatchFromDB:(id)db {
id wb = [[[self alloc] init] autorelease];
((LDBWritebatch *)wb)->_db = [db retain];
id wb = [[self alloc] init];
((LDBWritebatch *)wb)->_db = db;
return wb;
}

Expand All @@ -42,14 +41,11 @@ - (instancetype) init {
}
- (void)dealloc {
if (_serial_queue) {
dispatch_release(_serial_queue);
_serial_queue = nil;
}
if (_db) {
[_db release];
_db = nil;
}
[super dealloc];
}

- (void) removeObjectForKey:(id)key {
Expand Down
4 changes: 2 additions & 2 deletions Classes/LevelDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ NSData * NSDataFromLevelDBKey (LevelDBKey * key);
/**
The path of the database on disk
*/
@property (nonatomic, retain) NSString *path;
@property (nonatomic, copy) NSString *path;

/**
The name of the database.
*/
@property (nonatomic, retain) NSString *name;
@property (nonatomic, copy) NSString *name;

/**
A boolean value indicating whether write operations should be synchronous (flush to disk before returning).
Expand Down
29 changes: 9 additions & 20 deletions Classes/LevelDB.mm
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ virtual void Delete(const leveldb::Slice& key) {
}

NSString * NSStringFromLevelDBKey(LevelDBKey * key) {
return [[[NSString alloc] initWithBytes:key->data
return [[NSString alloc] initWithBytes:key->data
length:key->length
encoding:NSUTF8StringEncoding] autorelease];
encoding:NSUTF8StringEncoding];
}
NSData * NSDataFromLevelDBKey(LevelDBKey * key) {
return [NSData dataWithBytes:key->data length:key->length];
Expand Down Expand Up @@ -117,9 +117,8 @@ - (id) initWithPath:(NSString *)path andName:(NSString *)name {
- (id) initWithPath:(NSString *)path name:(NSString *)name andOptions:(LevelDBOptions)opts {
self = [super init];
if (self) {
_name = [name retain];
_path = [path retain];

_path = path;
_name = name;
leveldb::Options options;

options.create_if_missing = opts.createIfMissing;
Expand All @@ -145,8 +144,6 @@ - (id) initWithPath:(NSString *)path name:(NSString *)name andOptions:(LevelDBOp
attributes:nil
error:&crError];
if (!success) {
[_name release];
[_path release];
NSLog(@"Problem creating parent directory: %@", crError);
return nil;
}
Expand All @@ -162,8 +159,6 @@ - (id) initWithPath:(NSString *)path name:(NSString *)name andOptions:(LevelDBOp
writeOptions.sync = false;

if(!status.ok()) {
[_name release];
[_path release];
NSLog(@"Problem creating LevelDB database: %s", status.ToString().c_str());
return nil;
}
Expand Down Expand Up @@ -193,7 +188,7 @@ + (id) databaseInLibraryWithName:(NSString *)name {
+ (id) databaseInLibraryWithName:(NSString *)name
andOptions:(LevelDBOptions)opts {
NSString *path = [getLibraryPath() stringByAppendingPathComponent:name];
LevelDB *ldb = [[[self alloc] initWithPath:path name:name andOptions:opts] autorelease];
LevelDB *ldb = [[self alloc] initWithPath:path name:name andOptions:opts];
return ldb;
}

Expand Down Expand Up @@ -244,7 +239,7 @@ - (void) addEntriesFromDictionary:(NSDictionary *)dictionary {
#pragma mark - Write batches

- (LDBWritebatch *)newWritebatch {
return [[LDBWritebatch writeBatchFromDB:self] retain];
return [LDBWritebatch writeBatchFromDB:self];
}

- (void) applyWritebatch:(LDBWritebatch *)writeBatch {
Expand All @@ -259,7 +254,6 @@ - (void)performWritebatch:(void (^)(LDBWritebatch *wb))block {
LDBWritebatch *wb = [self newWritebatch];
block(wb);
[wb apply];
[wb release];
}

#pragma mark - Getters
Expand Down Expand Up @@ -382,14 +376,14 @@ - (void) removeAllObjectsWithPrefix:(id)prefix {
#pragma mark - Selection

- (NSArray *)allKeys {
NSMutableArray *keys = [[[NSMutableArray alloc] init] autorelease];
NSMutableArray *keys = [[NSMutableArray alloc] init];
[self enumerateKeysUsingBlock:^(LevelDBKey *key, BOOL *stop) {
[keys addObject:NSDataFromLevelDBKey(key)];
}];
return [NSArray arrayWithArray:keys];
}
- (NSArray *)keysByFilteringWithPredicate:(NSPredicate *)predicate {
NSMutableArray *keys = [[[NSMutableArray alloc] init] autorelease];
NSMutableArray *keys = [[NSMutableArray alloc] init];
[self enumerateKeysAndObjectsBackward:NO lazily:NO
startingAtKey:nil
filteredByPredicate:predicate
Expand All @@ -416,7 +410,7 @@ - (NSDictionary *)dictionaryByFilteringWithPredicate:(NSPredicate *)predicate {
}

- (LDBSnapshot *) newSnapshot {
return [[LDBSnapshot snapshotFromDB:self] retain];
return [LDBSnapshot snapshotFromDB:self];
}

#pragma mark - Enumeration
Expand Down Expand Up @@ -678,11 +672,6 @@ - (BOOL) closed {
}
- (void) dealloc {
[self close];
if (_path) [_path release];
if (_name) [_name release];
if (_encoder) [_encoder release];
if (_decoder) [_decoder release];
[super dealloc];
}

@end