This repository has been archived by the owner on Apr 6, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from jasonhotsauce/performance
Performance
- Loading branch information
Showing
5 changed files
with
136 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// LNLocalizedStringCollectionOperation.h | ||
// Lin | ||
// | ||
// Created by Wenbin Zhang on 3/7/14. | ||
// Copyright (c) 2014 Tanaka Katsuma. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@class IDEIndex; | ||
|
||
typedef void(^LNLocalizedStringCollectionCompletionBlock)(NSString *workspacePath, NSArray *collections); | ||
|
||
@interface LNLocalizedStringCollectionOperation : NSOperation | ||
|
||
@property (nonatomic, strong) IDEIndex *index; | ||
@property (nonatomic, copy) LNLocalizedStringCollectionCompletionBlock collectionCompletedBlock; | ||
|
||
- (instancetype)initWithIndex:(IDEIndex *)index; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// | ||
// LNLocalizedStringCollectionOperation.m | ||
// Lin | ||
// | ||
// Created by Wenbin Zhang on 3/7/14. | ||
// Copyright (c) 2014 Tanaka Katsuma. All rights reserved. | ||
// | ||
|
||
#import "LNLocalizedStringCollectionOperation.h" | ||
#import "IDEIndex.h" | ||
#import "IDEWorkspace.h" | ||
#import "IDEIndexCollection.h" | ||
#import "DVTFilePath.h" | ||
#import "LNLocalizationCollection.h" | ||
|
||
@interface LNLocalizedStringCollectionOperation () | ||
|
||
@property (nonatomic, strong) NSArray *collections; | ||
@property (nonatomic, strong) NSString *workspaceFilePath; | ||
@end | ||
|
||
@implementation LNLocalizedStringCollectionOperation | ||
|
||
- (instancetype)initWithIndex:(IDEIndex *)index | ||
{ | ||
self = [super init]; | ||
if (self) { | ||
self.index = index; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)main | ||
{ | ||
@autoreleasepool { | ||
if (self.isCancelled) { | ||
return; | ||
} | ||
|
||
if (!self.index) { | ||
return; | ||
} | ||
[self processLocalizedString]; | ||
|
||
if (self.isCancelled) { | ||
return; | ||
} | ||
|
||
if (self.collectionCompletedBlock) { | ||
dispatch_async(dispatch_get_main_queue(), ^{ | ||
self.collectionCompletedBlock(self.workspaceFilePath, self.collections); | ||
}); | ||
} | ||
|
||
[self cleanup]; | ||
} | ||
} | ||
|
||
- (void)processLocalizedString | ||
{ | ||
IDEWorkspace *workspace = [self.index valueForKey:@"_workspace"]; | ||
DVTFilePath *representingFilePath = workspace.representingFilePath; | ||
self.workspaceFilePath = representingFilePath.pathString; | ||
NSMutableArray *mutableCollections = [[NSMutableArray alloc] init]; | ||
|
||
if (self.workspaceFilePath) { | ||
NSString *projectRootPath = [[self.workspaceFilePath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent]; | ||
|
||
// Find .strings files | ||
IDEIndexCollection *indexCollection = [self.index filesContaining:@".strings" anchorStart:NO anchorEnd:NO subsequence:NO ignoreCase:YES cancelWhen:nil]; | ||
|
||
for (DVTFilePath *filePath in indexCollection) { | ||
if (self.isCancelled) { | ||
return; | ||
} | ||
NSString *pathString = filePath.pathString; | ||
|
||
BOOL parseStringsFilesOutsideWorkspaceProject = YES; | ||
if (parseStringsFilesOutsideWorkspaceProject || | ||
(!parseStringsFilesOutsideWorkspaceProject && [pathString rangeOfString:projectRootPath].location != NSNotFound)) { | ||
// Create localization collection | ||
LNLocalizationCollection *collection = [LNLocalizationCollection localizationCollectionWithContentsOfFile:pathString]; | ||
[mutableCollections addObject:collection]; | ||
} | ||
} | ||
self.collections = [mutableCollections copy]; | ||
} | ||
} | ||
|
||
- (void)cleanup | ||
{ | ||
self.index = nil; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters