Skip to content

Commit 2f16b11

Browse files
committed
Speed improvements.
1 parent 8e85a00 commit 2f16b11

File tree

9 files changed

+175
-92
lines changed

9 files changed

+175
-92
lines changed

Source/XCGroup.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ - (void)removeProductsGroupFromProject:(NSString*)key
685685
- (NSDictionary*)makeFileReferenceWithPath:(NSString*)path name:(NSString*)name type:(XcodeSourceFileType)type
686686
{
687687
NSMutableDictionary* reference = [NSMutableDictionary dictionary];
688-
reference[@"isa"] = [NSString stringFromMemberType:PBXFileReferenceType];
688+
reference[@"isa"] = [NSString xce_stringFromMemberType:PBXFileReferenceType];
689689
reference[@"fileEncoding"] = @"4";
690690
reference[@"lastKnownFileType"] = NSStringFromXCSourceFileType(type);
691691
if (name != nil)
@@ -704,7 +704,7 @@ - (NSDictionary*)makeFileReferenceWithPath:(NSString*)path name:(NSString*)name
704704
- (NSDictionary*)asDictionary
705705
{
706706
NSMutableDictionary* groupData = [NSMutableDictionary dictionary];
707-
groupData[@"isa"] = [NSString stringFromMemberType:PBXGroupType];
707+
groupData[@"isa"] = [NSString xce_stringFromMemberType:PBXGroupType];
708708
groupData[@"sourceTree"] = @"<group>";
709709

710710
if (_alias != nil)
@@ -728,7 +728,7 @@ - (NSDictionary*)asDictionary
728728
- (XcodeMemberType)typeForKey:(NSString*)key
729729
{
730730
NSDictionary* obj = [[_project objects] valueForKey:key];
731-
return [[obj valueForKey:@"isa"] asMemberType];
731+
return [[obj valueForKey:@"isa"] xce_asMemberType];
732732
}
733733

734734
- (void)addSourceFile:(XCSourceFile*)sourceFile toTargets:(NSArray*)targets

Source/XCProject+SubProject.m

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ - (NSString *)referenceProxyKeyForName:(NSString *)name
3131
{
3232
__block NSString *result = nil;
3333
[[self objects] enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary *obj, BOOL *stop) {
34-
if ([[obj valueForKey:@"isa"] asMemberType] == PBXReferenceProxyType) {
34+
if ([[obj valueForKey:@"isa"] xce_hasReferenceProxyType]) {
3535
NSString *candidate = [obj valueForKey:@"path"];
3636
if ([candidate isEqualToString:name]) {
3737
result = key;
@@ -48,7 +48,7 @@ - (NSArray *)buildProductsForTargets:(NSString *)xcodeprojKey
4848
{
4949
NSMutableArray *results = [[NSMutableArray alloc] init];
5050
[[self objects] enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary *obj, BOOL *stop) {
51-
if ([[obj valueForKey:@"isa"] asMemberType] == PBXReferenceProxyType) {
51+
if ([[obj valueForKey:@"isa"] xce_hasReferenceProxyType]) {
5252
// make sure it belongs to the xcodeproj we're adding
5353
NSString *remoteRef = [obj valueForKey:@"remoteRef"];
5454
NSDictionary *containerProxy = [[self objects] valueForKey:remoteRef];
@@ -91,7 +91,7 @@ - (NSArray *)keysForProjectObjectsOfType:(XcodeMemberType)memberType withIdentif
9191
{
9292
__block NSMutableArray *returnValue = [[NSMutableArray alloc] init];
9393
[[self objects] enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary *obj, BOOL *stop) {
94-
if ([[obj valueForKey:@"isa"] asMemberType] == memberType) {
94+
if ([[obj valueForKey:@"isa"] xce_asMemberType] == memberType) {
9595
if (memberType == PBXContainerItemProxyType) {
9696
if ([[obj valueForKey:@"containerPortal"] isEqualToString:identifier]) {
9797
[returnValue addObject:key];
@@ -131,20 +131,21 @@ - (NSArray *)keysForProjectObjectsOfType:(XcodeMemberType)memberType withIdentif
131131
[returnValue addObject:key];
132132
}
133133
else {
134-
[NSException raise:NSInvalidArgumentException format:@"Unrecognized member type %@",
135-
[NSString stringFromMemberType:memberType]];
134+
[NSException raise:NSInvalidArgumentException
135+
format:@"Unrecognized member type %@", [NSString xce_stringFromMemberType:memberType]];
136136
}
137137
}
138138
}];
139139
if (singleton && [returnValue count] > 1) {
140140
[NSException raise:NSGenericException
141-
format:@"Searched for one instance of member type %@ with value %@, but found %ld",
142-
[NSString stringFromMemberType:memberType], identifier, (unsigned long) [returnValue count]];
141+
format:@"Searched for one instance of member type %@ with value %@, but found %ld",
142+
[NSString xce_stringFromMemberType:memberType], identifier,
143+
(unsigned long) [returnValue count]];
143144
}
144145
if (required && [returnValue count] == 0) {
145146
[NSException raise:NSGenericException
146-
format:@"Searched for instances of member type %@ with value %@, but did not find any",
147-
[NSString stringFromMemberType:memberType], identifier];
147+
format:@"Searched for instances of member type %@ with value %@, but did not find any",
148+
[NSString xce_stringFromMemberType:memberType], identifier];
148149
}
149150
return returnValue;
150151
}
@@ -165,7 +166,7 @@ - (NSString *)containerItemProxyKeyForName:(NSString *)name proxyType:(NSString
165166
{
166167
NSMutableArray *results = [[NSMutableArray alloc] init];
167168
[[self objects] enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary *obj, BOOL *stop) {
168-
if ([[obj valueForKey:@"isa"] asMemberType] == PBXContainerItemProxyType) {
169+
if ([[obj valueForKey:@"isa"] xce_hasContainerItemProxyType]) {
169170
NSString *remoteInfo = [obj valueForKey:@"remoteInfo"];
170171
NSString *proxy = [obj valueForKey:@"proxyType"];
171172
if ([remoteInfo isEqualToString:name] && [proxy isEqualToString:proxyType]) {
@@ -208,7 +209,7 @@ - (NSString *)makeContainerItemProxyForName:(NSString *)name fileRef:(NSString *
208209
}
209210
// make new one
210211
NSMutableDictionary *proxy = [NSMutableDictionary dictionary];
211-
proxy[@"isa"] = [NSString stringFromMemberType:PBXContainerItemProxyType];
212+
proxy[@"isa"] = [NSString xce_stringFromMemberType:PBXContainerItemProxyType];
212213
proxy[@"containerPortal"] = fileRef;
213214
proxy[@"proxyType"] = proxyType;
214215
// give it a random key - the keys xcode puts here are not in the project file anywhere else
@@ -237,7 +238,7 @@ - (void)makeReferenceProxyForContainerItemProxy:(NSString *)containerItemProxyKe
237238
}
238239
// make new one
239240
NSMutableDictionary *proxy = [NSMutableDictionary dictionary];
240-
proxy[@"isa"] = [NSString stringFromMemberType:PBXReferenceProxyType];
241+
proxy[@"isa"] = [NSString xce_stringFromMemberType:PBXReferenceProxyType];
241242
proxy[@"fileType"] = [buildProductReference valueForKey:@"explicitFileType"];
242243
proxy[@"path"] = path;
243244
proxy[@"remoteRef"] = containerItemProxyKey;
@@ -268,7 +269,7 @@ - (NSString *)makeTargetDependency:(NSString *)name forContainerItemProxyKey:(NS
268269
}
269270
// make new one
270271
NSMutableDictionary *targetDependency = [NSMutableDictionary dictionary];
271-
targetDependency[@"isa"] = [NSString stringFromMemberType:PBXTargetDependencyType];
272+
targetDependency[@"isa"] = [NSString xce_stringFromMemberType:PBXTargetDependencyType];
272273
targetDependency[@"name"] = name;
273274
targetDependency[@"targetProxy"] = containerItemProxyKey;
274275
NSString *targetDependencyKey = [[XCKeyBuilder forItemNamed:[NSString stringWithFormat:@"%@-targetProxy", keyName]]

Source/XCProject.m

Lines changed: 45 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,18 @@ - (NSArray*)files
6666
NSMutableArray* results = [NSMutableArray array];
6767
[[self objects] enumerateKeysAndObjectsUsingBlock:^(NSString* key, NSDictionary* obj, BOOL* stop)
6868
{
69-
if ([[obj valueForKey:@"isa"] asMemberType] == PBXFileReferenceType)
69+
if ([[obj valueForKey:@"isa"] xce_hasFileReferenceType])
7070
{
7171
XcodeSourceFileType fileType = XCSourceFileTypeFromStringRepresentation([obj valueForKey:@"lastKnownFileType"]);
7272
NSString* path = [obj valueForKey:@"path"];
7373
NSString* sourceTree = [obj valueForKey:@"sourceTree"];
74-
[results addObject:[XCSourceFile sourceFileWithProject:self key:key type:fileType name:path
75-
sourceTree:(sourceTree ? sourceTree : @"<group>") path:nil]];
74+
XCSourceFile* sourceFile = [XCSourceFile sourceFileWithProject:self
75+
key:key
76+
type:fileType
77+
name:path
78+
sourceTree:(sourceTree ?: @"<group>")
79+
path:nil];
80+
[results addObject:sourceFile];
7681
}
7782
}];
7883
return results;
@@ -81,20 +86,24 @@ - (NSArray*)files
8186
- (XCSourceFile*)fileWithKey:(NSString*)key
8287
{
8388
NSDictionary* obj = [[self objects] valueForKey:key];
84-
if (obj && ([[obj valueForKey:@"isa"] asMemberType] == PBXFileReferenceType || [[obj valueForKey:@"isa"] asMemberType] ==
85-
PBXReferenceProxyType))
89+
if (obj && [[obj valueForKey:@"isa"] xce_hasFileReferenceOrReferenceProxyType])
8690
{
8791
XcodeSourceFileType fileType = XCSourceFileTypeFromStringRepresentation([obj valueForKey:@"lastKnownFileType"]);
8892

8993
NSString* name = [obj valueForKey:@"name"];
9094
NSString* sourceTree = [obj valueForKey:@"sourceTree"];
95+
NSString* path = [obj valueForKey:@"path"];
9196

9297
if (name == nil)
9398
{
94-
name = [obj valueForKey:@"path"];
99+
name = path;
95100
}
96-
return [XCSourceFile sourceFileWithProject:self key:key type:fileType name:name sourceTree:(sourceTree ? sourceTree : @"<group>")
97-
path:[obj valueForKey:@"path"]];
101+
return [XCSourceFile sourceFileWithProject:self
102+
key:key
103+
type:fileType
104+
name:name
105+
sourceTree:(sourceTree ?: @"<group>")
106+
path:path];
98107
}
99108
return nil;
100109
}
@@ -150,14 +159,18 @@ - (NSString*)filePath
150159

151160
- (NSArray*)groups
152161
{
153-
154162
NSMutableArray* results = [[NSMutableArray alloc] init];
155-
[[_dataStore objectForKey:@"objects"] enumerateKeysAndObjectsUsingBlock:^(NSString* key, NSDictionary* obj, BOOL* stop)
163+
[[self objects] enumerateKeysAndObjectsUsingBlock:^(NSString* key, NSDictionary* obj, BOOL* stop)
156164
{
157-
158-
if ([[obj valueForKey:@"isa"] asMemberType] == PBXGroupType || [[obj valueForKeyPath:@"isa"] asMemberType] == PBXVariantGroupType)
165+
if ([[obj valueForKey:@"isa"] xce_hasGroupType])
159166
{
160-
[results addObject:[self groupWithKey:key]];
167+
XCGroup* group = _groups[key];
168+
if (group == nil)
169+
{
170+
group = [self createGroupWithDictionary:obj forKey:key];
171+
_groups[key] = group;
172+
}
173+
[results addObject:group];
161174
}
162175
}];
163176
return results;
@@ -205,15 +218,10 @@ - (XCGroup*)groupWithKey:(NSString*)key
205218
}
206219

207220
NSDictionary* obj = [[self objects] objectForKey:key];
208-
if (obj && ([[obj valueForKey:@"isa"] asMemberType] == PBXGroupType || [[obj valueForKey:@"isa"] asMemberType] == PBXVariantGroupType))
221+
if (obj && [[obj valueForKey:@"isa"] xce_hasGroupType])
209222
{
210-
211-
NSString* name = [obj valueForKey:@"name"];
212-
NSString* path = [obj valueForKey:@"path"];
213-
NSArray* children = [obj valueForKey:@"children"];
214-
XCGroup* group = [XCGroup groupWithProject:self key:key alias:name path:path children:children];
215-
216-
[_groups setObject:group forKey:key];
223+
XCGroup* group = [self createGroupWithDictionary:obj forKey:key];
224+
_groups[key] = group;
217225

218226
return group;
219227
}
@@ -251,7 +259,7 @@ - (XCGroup*)groupWithSourceFile:(XCSourceFile*)sourceFile
251259
//TODO: search backwards.
252260
- (XCGroup*)groupWithPathFromRoot:(NSString*)path
253261
{
254-
NSArray* pathItems = [path componentsSeparatedByString:@"/"];
262+
NSArray* pathItems = [path pathComponents];
255263
XCGroup* currentGroup = [self rootGroup];
256264
for (NSString* pathItem in pathItems)
257265
{
@@ -268,6 +276,15 @@ - (XCGroup*)groupWithPathFromRoot:(NSString*)path
268276
return currentGroup;
269277
}
270278

279+
- (XCGroup*)createGroupWithDictionary:(NSDictionary*)dictionary forKey:(NSString*)key
280+
{
281+
return [XCGroup groupWithProject:self
282+
key:key
283+
alias:[dictionary valueForKey:@"name"]
284+
path:[dictionary valueForKey:@"path"]
285+
children:[dictionary valueForKey:@"children"]];
286+
}
287+
271288

272289
//-------------------------------------------------------------------------------------------
273290
#pragma mark targets
@@ -280,11 +297,13 @@ - (NSArray*)targets
280297
_targets = [[NSMutableArray alloc] init];
281298
[[self objects] enumerateKeysAndObjectsUsingBlock:^(NSString* key, NSDictionary* obj, BOOL* stop)
282299
{
283-
if ([[obj valueForKey:@"isa"] asMemberType] == PBXNativeTargetType)
300+
if ([[obj valueForKey:@"isa"] xce_hasNativeTargetType])
284301
{
285-
XCTarget* target =
286-
[XCTarget targetWithProject:self key:key name:[obj valueForKey:@"name"] productName:[obj valueForKey:@"productName"]
287-
productReference:[obj valueForKey:@"productReference"]];
302+
XCTarget* target = [XCTarget targetWithProject:self
303+
key:key
304+
name:[obj valueForKey:@"name"]
305+
productName:[obj valueForKey:@"productName"]
306+
productReference:[obj valueForKey:@"productReference"]];
288307
[_targets addObject:target];
289308
}
290309
}];

Source/XCProjectBuildConfig.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ + (NSDictionary*)buildConfigurationsFromArray:(NSArray*)array inProject:(XCProje
3030
{
3131
NSDictionary* buildConfiguration = [[project objects] objectForKey:buildConfigurationKey];
3232

33-
if ([[buildConfiguration valueForKey:@"isa"] asMemberType] == XCBuildConfigurationType)
33+
if ([[buildConfiguration valueForKey:@"isa"] xce_hasBuildConfigurationType])
3434
{
3535
XCProjectBuildConfig * configuration = [configurations objectForKey:[buildConfiguration objectForKey:@"name"]];
3636
if (!configuration)

Source/XCSourceFile.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ - (BOOL)isBuildFile
100100
if ([self canBecomeBuildFile] && _isBuildFile == nil) {
101101
_isBuildFile = @NO;
102102
[[_project objects] enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary *obj, BOOL *stop) {
103-
if ([[obj valueForKey:@"isa"] asMemberType] == PBXBuildFileType) {
103+
if ([[obj valueForKey:@"isa"] xce_hasBuildFileType]) {
104104
if ([[obj valueForKey:@"fileRef"] isEqualToString:_key]) {
105105
_isBuildFile = nil;
106106

@@ -139,7 +139,7 @@ - (NSString *)buildFileKey
139139
{
140140
if (_buildFileKey == nil) {
141141
[[_project objects] enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary *obj, BOOL *stop) {
142-
if ([[obj valueForKey:@"isa"] asMemberType] == PBXBuildFileType) {
142+
if ([[obj valueForKey:@"isa"] xce_hasBuildFileType]) {
143143
if ([[obj valueForKey:@"fileRef"] isEqualToString:_key]) {
144144
_buildFileKey = [key copy];
145145
}
@@ -156,7 +156,7 @@ - (void)becomeBuildFile
156156
if (![self isBuildFile]) {
157157
if ([self canBecomeBuildFile]) {
158158
NSMutableDictionary *sourceBuildFile = [NSMutableDictionary dictionary];
159-
sourceBuildFile[@"isa"] = [NSString stringFromMemberType:PBXBuildFileType];
159+
sourceBuildFile[@"isa"] = [NSString xce_stringFromMemberType:PBXBuildFileType];
160160
sourceBuildFile[@"fileRef"] = _key;
161161
NSString *buildFileKey = [[XCKeyBuilder forItemNamed:[_name stringByAppendingString:@".buildFile"]] build];
162162
[_project objects][buildFileKey] = sourceBuildFile;
@@ -176,7 +176,7 @@ - (void)setCompilerFlags:(NSString *)value
176176
{
177177
NSMutableDictionary *objectArrayCopy = [[_project objects] mutableCopy];
178178
[objectArrayCopy enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary *obj, BOOL *stop) {
179-
if ([[obj valueForKey:@"isa"] asMemberType] == PBXBuildFileType) {
179+
if ([[obj valueForKey:@"isa"] xce_hasBuildFileType]) {
180180
if ([obj[@"fileRef"] isEqualToString:self.key]) {
181181
NSMutableDictionary *replaceBuildFile = [NSMutableDictionary dictionaryWithDictionary:obj];
182182
NSDictionary *compilerFlagsDict = @{@"COMPILER_FLAGS" : value};

Source/XCSubProjectDefinition.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ - (NSArray *)buildProductNames
7979
NSMutableArray *results = [NSMutableArray array];
8080
NSDictionary *objects = [_subProject objects];
8181
[objects enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary *obj, BOOL *stop) {
82-
if ([[obj valueForKey:@"isa"] asMemberType] == PBXProjectType) {
82+
if ([[obj valueForKey:@"isa"] xce_hasProjectType]) {
8383
NSString *productRefGroupKey = [obj valueForKey:@"productRefGroup"];
8484
NSDictionary *products = [objects valueForKey:productRefGroupKey];
8585
NSArray *children = [products valueForKey:@"children"];

Source/XCTarget.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ - (NSArray*)resources
5757
for (NSString* buildPhaseKey in [[[_project objects] objectForKey:_key] objectForKey:@"buildPhases"])
5858
{
5959
NSDictionary* buildPhase = [[_project objects] objectForKey:buildPhaseKey];
60-
if ([[buildPhase valueForKey:@"isa"] asMemberType] == PBXResourcesBuildPhaseType)
60+
if ([[buildPhase valueForKey:@"isa"] xce_hasResourcesBuildPhaseType])
6161
{
6262
for (NSString* buildFileKey in [buildPhase objectForKey:@"files"])
6363
{
@@ -107,8 +107,7 @@ - (NSArray*)members
107107
for (NSString* buildPhaseKey in [[[_project objects] objectForKey:_key] objectForKey:@"buildPhases"])
108108
{
109109
NSDictionary* buildPhase = [[_project objects] objectForKey:buildPhaseKey];
110-
if ([[buildPhase valueForKey:@"isa"] asMemberType] == PBXSourcesBuildPhaseType ||
111-
[[buildPhase valueForKey:@"isa"] asMemberType] == PBXFrameworksBuildPhaseType)
110+
if ([[buildPhase valueForKey:@"isa"] xce_hasSourcesOrFrameworksBuildPhaseType])
112111
{
113112
for (NSString* buildFileKey in [buildPhase objectForKey:@"files"])
114113
{
@@ -132,7 +131,7 @@ - (void)addMember:(XCSourceFile*)member
132131
for (NSString* buildPhaseKey in [target objectForKey:@"buildPhases"])
133132
{
134133
NSMutableDictionary* buildPhase = [[_project objects] objectForKey:buildPhaseKey];
135-
if ([[buildPhase valueForKey:@"isa"] asMemberType] == [member buildPhase])
134+
if ([[buildPhase valueForKey:@"isa"] xce_asMemberType] == [member buildPhase])
136135
{
137136

138137
NSMutableArray* files = [buildPhase objectForKey:@"files"];
@@ -294,7 +293,7 @@ - (XCSourceFile*)buildFileWithKey:(NSString*)theKey
294293
NSDictionary* obj = [[_project objects] valueForKey:theKey];
295294
if (obj)
296295
{
297-
if ([[obj valueForKey:@"isa"] asMemberType] == PBXBuildFileType)
296+
if ([[obj valueForKey:@"isa"] xce_hasBuildFileType])
298297
{
299298
return [_project fileWithKey:[obj valueForKey:@"fileRef"]];
300299
}

Source/XcodeMemberType.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,21 @@ typedef enum
3333

3434
@interface NSString (XcodeMemberTypeExtensions)
3535

36-
+ (NSString*)stringFromMemberType:(XcodeMemberType)nodeType;
37-
38-
- (XcodeMemberType)asMemberType;
36+
+ (NSString*)xce_stringFromMemberType:(XcodeMemberType)nodeType;
37+
38+
- (XcodeMemberType)xce_asMemberType;
39+
40+
- (BOOL)xce_hasFileReferenceType;
41+
- (BOOL)xce_hasFileReferenceOrReferenceProxyType;
42+
- (BOOL)xce_hasReferenceProxyType;
43+
- (BOOL)xce_hasGroupType;
44+
- (BOOL)xce_hasProjectType;
45+
- (BOOL)xce_hasNativeTargetType;
46+
- (BOOL)xce_hasBuildFileType;
47+
- (BOOL)xce_hasBuildConfigurationType;
48+
- (BOOL)xce_hasContainerItemProxyType;
49+
- (BOOL)xce_hasResourcesBuildPhaseType;
50+
- (BOOL)xce_hasSourcesOrFrameworksBuildPhaseType;
3951

4052
@end
4153

0 commit comments

Comments
 (0)