* Optimized Olivier's MYDirectoryWatcher fix (by caching the watcher's standardized path)
authorJens Alfke <jens@mooseyard.com>
Thu May 14 20:44:32 2009 -0700 (2009-05-14)
changeset 312068331949ee
parent 30 2befbe36c746
child 32 222393534845
* Optimized Olivier's MYDirectoryWatcher fix (by caching the watcher's standardized path)
* Added -[NSData my_UTF8ToString] to CollectionUtils.
CollectionUtils.h
CollectionUtils.m
MYDirectoryWatcher.h
MYDirectoryWatcher.m
     1.1 --- a/CollectionUtils.h	Tue May 12 14:38:30 2009 +0200
     1.2 +++ b/CollectionUtils.h	Thu May 14 20:44:32 2009 -0700
     1.3 @@ -68,6 +68,12 @@
     1.4  @end
     1.5  
     1.6  
     1.7 +@interface NSData (MYUtils)
     1.8 +- (NSString*) my_UTF8ToString;
     1.9 +@end
    1.10 +
    1.11 +
    1.12 +
    1.13  #pragma mark -
    1.14  #pragma mark FOREACH:
    1.15      
     2.1 --- a/CollectionUtils.m	Tue May 12 14:38:30 2009 +0200
     2.2 +++ b/CollectionUtils.m	Thu May 14 20:44:32 2009 -0700
     2.3 @@ -290,6 +290,16 @@
     2.4  
     2.5  
     2.6  
     2.7 +@implementation NSData (MYUtils)
     2.8 +
     2.9 +- (NSString*) my_UTF8ToString {
    2.10 +    return [[[NSString alloc] initWithData: self encoding: NSUTF8StringEncoding] autorelease];
    2.11 +}
    2.12 +
    2.13 +@end
    2.14 +
    2.15 +
    2.16 +
    2.17  #import "Test.h"
    2.18  
    2.19  TestCase(CollectionUtils) {
     3.1 --- a/MYDirectoryWatcher.h	Tue May 12 14:38:30 2009 +0200
     3.2 +++ b/MYDirectoryWatcher.h	Thu May 14 20:44:32 2009 -0700
     3.3 @@ -11,7 +11,7 @@
     3.4  /* A wrapper for FSEvents, which notifies its delegate when filesystem changes occur. */
     3.5  @interface MYDirectoryWatcher : NSObject 
     3.6  {
     3.7 -    NSString *_path;
     3.8 +    NSString *_path, *_standardizedPath;
     3.9      id _target;
    3.10      SEL _action;
    3.11      UInt64 _lastEventID;
     4.1 --- a/MYDirectoryWatcher.m	Tue May 12 14:38:30 2009 +0200
     4.2 +++ b/MYDirectoryWatcher.m	Thu May 14 20:44:32 2009 -0700
     4.3 @@ -35,6 +35,7 @@
     4.4      self = [super init];
     4.5      if (self != nil) {
     4.6          _path = path.copy;
     4.7 +        _standardizedPath = [_path stringByStandardizingPath];
     4.8          _target = target;
     4.9          _action = action;
    4.10          _latency = 5.0;
    4.11 @@ -59,6 +60,10 @@
    4.12  
    4.13  @synthesize path=_path, latency=_latency, lastEventID=_lastEventID;
    4.14  
    4.15 +- (NSString*) standardizedPath {
    4.16 +    return _standardizedPath;
    4.17 +}
    4.18 +
    4.19  
    4.20  - (BOOL) start
    4.21  {
    4.22 @@ -191,7 +196,7 @@
    4.23  
    4.24  - (NSString*) relativePath
    4.25  {
    4.26 -    NSString *base = [watcher.path stringByStandardizingPath];
    4.27 +    NSString *base = watcher.standardizedPath;
    4.28      NSString *standardizedPath = [path stringByStandardizingPath];
    4.29      if( ! [standardizedPath hasPrefix: base] )
    4.30          return nil;