用于初始化 NSCompoundPredicate 的数组中子谓词的顺序会影响效率吗?
例子:
NSString * str = [self getAStr];
NSManagedObject * mo = [self getAMo];
NSString * fmt = @"(stringAttribute ==[cd] %@) AND (relationships CONTAINS %@)";
NSString * fmt2 = @"relationships.@count != 0";
NSPredicate * p1 = [NSPredicate predicateWithFormat:fmt,str,mo];//expensive predicate
NSPredicate * p2 = [NSPredicate predicateWithFormat:fmt2,nil];//less expensive predicate
NSCompoundPredicate * cp = [NSCompoundPredicate andPredicateWithSubpredicates:@[p1,p2];
[self fetchSomethingWithPredicate:cp];
在上面的例子中,p1 和 p2 的顺序会改变复合谓词的计算方式吗?显然,首先评估 p2 会更有效,假设如果 p2 评估为 false,则 p1 将被忽略。