Skip to content

Commit 5190521

Browse files
author
lijianghuai
committed
【bugfix】bugly 中发现 insert 的时候用 autorelease 还是会出现 AutoreleasePoolPage::releaseUntil 相关闪退,并且 insert 和 update 临时对象并不对,所以不继续包在 autorelease pool 内。
在卡顿记录中 NSNumberFormatter numberFromString 的数量也不少,于是决定直接使用 string 的相关API 生成 NSNumber
1 parent f92dc47 commit 5190521

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

LKDBHelper.podspec.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "LKDBHelper",
3-
"version": "2.5.6",
3+
"version": "2.5.7",
44
"summary": "全自动的插入,查询,更新,删除, an automatic database operation thread-safe and not afraid of recursive deadlock",
55
"description": "全面支持 NSArray,NSDictionary, ModelClass, NSNumber, NSString, NSDate, NSData, UIColor, UIImage, CGRect, CGPoint, CGSize, NSRange, int,char,float, double, long.. 等属性的自动化操作(插入和查询)",
66
"homepage": "https://github.com/li6185377/LKDBHelper-SQLite-ORM",
@@ -10,7 +10,7 @@
1010
},
1111
"source": {
1212
"git": "https://github.com/li6185377/LKDBHelper-SQLite-ORM.git",
13-
"tag": "2.5.6"
13+
"tag": "2.5.7"
1414
},
1515
"platforms": {
1616
"ios": "5.0",

LKDBHelper/Helper/LKDBHelper.m

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,19 +1178,13 @@ - (NSMutableArray *)executeResult:(FMResultSet *)set Class:(Class)modelClass tab
11781178

11791179
#pragma mark - insert operation
11801180
- (BOOL)insertToDB:(NSObject *)model {
1181-
__block BOOL success = NO;
1182-
[self inAutoReleaseExecuteBlock:^{
1183-
success = [self insertBase:model];
1184-
}];
1181+
BOOL success = [self insertBase:model];
11851182
return success;
11861183
}
11871184

11881185
- (void)insertToDB:(NSObject *)model callback:(void (^)(BOOL))block {
11891186
LKDBCode_Async_Begin;
1190-
__block BOOL success = NO;
1191-
[sself inAutoReleaseExecuteBlock:^{
1192-
success = [sself insertBase:model];
1193-
}];
1187+
BOOL success = [sself insertBase:model];
11941188
if (block) {
11951189
block(success);
11961190
}
@@ -1303,19 +1297,13 @@ - (BOOL)insertBase:(NSObject *)model {
13031297

13041298
#pragma mark - update operation
13051299
- (BOOL)updateToDB:(NSObject *)model where:(id)where {
1306-
__block BOOL success = NO;
1307-
[self inAutoReleaseExecuteBlock:^{
1308-
success = [self updateToDBBase:model where:where];
1309-
}];
1300+
BOOL success = [self updateToDBBase:model where:where];
13101301
return success;
13111302
}
13121303

13131304
- (void)updateToDB:(NSObject *)model where:(id)where callback:(void (^)(BOOL))block {
13141305
LKDBCode_Async_Begin;
1315-
__block BOOL success = NO;
1316-
[sself inAutoReleaseExecuteBlock:^{
1317-
success = [sself updateToDBBase:model where:where];
1318-
}];
1306+
BOOL success = [sself updateToDBBase:model where:where];
13191307
if (block) {
13201308
block(success);
13211309
}

LKDBHelper/Helper/LKDBUtils.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,33 @@ NS_ASSUME_NONNULL_BEGIN
4343

4444
@end
4545

46+
47+
#pragma mark - 数据格式化相关,可 method swizzle 做逻辑替换
48+
49+
@interface LKDateFormatter : NSDateFormatter
50+
51+
///由于 NSDateFormatter 相关API 并不是线程安全的
52+
@property (nonatomic, assign) dispatch_semaphore_t lock;
53+
54+
@end
55+
56+
@interface LKNumberFormatter : NSNumberFormatter
57+
58+
@end
59+
4660
/// 需要外部实现对应 API
47-
@interface LKDBUtils (output)
61+
@interface LKDBUtils (Events)
4862

4963
// LKDateFormatter 创建完毕, 可以修改对应属性
50-
+ (void)onCreateWithDateFormatter:(NSDateFormatter *)dateFormatter;
64+
+ (void)onCreateWithDateFormatter:(LKDateFormatter *)dateFormatter;
5165

52-
// NSNumberFormatter 创建完毕, 可以修改对应属性
53-
+ (void)onCreateWithNumberFormatter:(NSNumberFormatter *)numberFormatter;
66+
// LKNumberFormatter 创建完毕, 可以修改对应属性
67+
+ (void)onCreateWithNumberFormatter:(LKNumberFormatter *)numberFormatter;
5468

5569
@end
5670

71+
#pragma mark - Types
72+
5773
#ifdef DEBUG
5874
#ifdef NSLog
5975
#define LKErrorLog(fmt, ...) NSLog(@"#LKDBHelper ERROR:\n" fmt, ##__VA_ARGS__);
@@ -101,6 +117,8 @@ static NSString *const LKDB_PValueKey = @"DB_PKeyValue";
101117
///Object-c type converted to SQLite type 把Object-c 类型 转换为sqlite 类型
102118
extern NSString *LKSQLTypeFromObjcType(NSString *objcType);
103119

120+
#pragma mark - Search Utils
121+
104122
@interface LKDBQueryParams : NSObject
105123

106124
///columns or array

LKDBHelper/Helper/LKDBUtils.m

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88

99
#import "LKDBUtils.h"
1010

11-
@interface LKDateFormatter : NSDateFormatter
12-
@property (nonatomic, assign) dispatch_semaphore_t lock;
13-
@end
14-
1511
@implementation LKDateFormatter
1612

1713
- (instancetype)init {
@@ -51,10 +47,6 @@ - (NSString *)stringFromDate:(NSDate *)date {
5147

5248
@end
5349

54-
@interface LKNumberFormatter : NSNumberFormatter
55-
56-
@end
57-
5850
@implementation LKNumberFormatter
5951

6052
- (instancetype)init {
@@ -76,9 +68,11 @@ - (NSString *)stringFromNumber:(NSNumber *)number {
7668
}
7769

7870
- (NSNumber *)numberFromString:(NSString *)string {
79-
NSNumber *number = [super numberFromString:string];
80-
if (!number) {
81-
number = @(string.doubleValue);
71+
NSNumber *number = nil;
72+
if ([string rangeOfString:@"."].length > 0) {
73+
number = [NSNumber numberWithDouble:string.doubleValue];
74+
} else {
75+
number = [NSNumber numberWithLongLong:string.longLongValue];
8276
}
8377
return number;
8478
}

LKDBHelper/Helper/NSObject+LKModel.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ - (id)modelGetValue:(LKDBProperty *)property {
146146
#endif
147147
} else if ([value isKindOfClass:[LKDBImage class]]) {
148148
long random = arc4random();
149-
long date = [[NSDate date] timeIntervalSince1970];
149+
long date = CFAbsoluteTimeGetCurrent();
150150
NSString *filename = [NSString stringWithFormat:@"img%ld%ld", date & 0xFFFFF, random & 0xFFF];
151151

152152
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
@@ -163,7 +163,7 @@ - (id)modelGetValue:(LKDBProperty *)property {
163163
returnValue = filename;
164164
} else if ([value isKindOfClass:[NSData class]]) {
165165
long random = arc4random();
166-
long date = [[NSDate date] timeIntervalSince1970];
166+
long date = CFAbsoluteTimeGetCurrent();
167167
NSString *filename = [NSString stringWithFormat:@"data%ld%ld", date & 0xFFFFF, random & 0xFFF];
168168

169169
[value writeToFile:[self.class getDBDataPathWithName:filename] atomically:YES];

0 commit comments

Comments
 (0)