# HG changeset patch # User Jens Alfke # Date 1242359072 25200 # Node ID 2068331949eed2079c24cc34bb3ac4cf3df6853d # Parent 2befbe36c746641c7a7c30f9e8531fb3d6cfcb3b * Optimized Olivier's MYDirectoryWatcher fix (by caching the watcher's standardized path) * Added -[NSData my_UTF8ToString] to CollectionUtils. diff -r 2befbe36c746 -r 2068331949ee CollectionUtils.h --- a/CollectionUtils.h Tue May 12 14:38:30 2009 +0200 +++ b/CollectionUtils.h Thu May 14 20:44:32 2009 -0700 @@ -68,6 +68,12 @@ @end +@interface NSData (MYUtils) +- (NSString*) my_UTF8ToString; +@end + + + #pragma mark - #pragma mark FOREACH: diff -r 2befbe36c746 -r 2068331949ee CollectionUtils.m --- a/CollectionUtils.m Tue May 12 14:38:30 2009 +0200 +++ b/CollectionUtils.m Thu May 14 20:44:32 2009 -0700 @@ -290,6 +290,16 @@ +@implementation NSData (MYUtils) + +- (NSString*) my_UTF8ToString { + return [[[NSString alloc] initWithData: self encoding: NSUTF8StringEncoding] autorelease]; +} + +@end + + + #import "Test.h" TestCase(CollectionUtils) { diff -r 2befbe36c746 -r 2068331949ee MYDirectoryWatcher.h --- a/MYDirectoryWatcher.h Tue May 12 14:38:30 2009 +0200 +++ b/MYDirectoryWatcher.h Thu May 14 20:44:32 2009 -0700 @@ -11,7 +11,7 @@ /* A wrapper for FSEvents, which notifies its delegate when filesystem changes occur. */ @interface MYDirectoryWatcher : NSObject { - NSString *_path; + NSString *_path, *_standardizedPath; id _target; SEL _action; UInt64 _lastEventID; diff -r 2befbe36c746 -r 2068331949ee MYDirectoryWatcher.m --- a/MYDirectoryWatcher.m Tue May 12 14:38:30 2009 +0200 +++ b/MYDirectoryWatcher.m Thu May 14 20:44:32 2009 -0700 @@ -35,6 +35,7 @@ self = [super init]; if (self != nil) { _path = path.copy; + _standardizedPath = [_path stringByStandardizingPath]; _target = target; _action = action; _latency = 5.0; @@ -59,6 +60,10 @@ @synthesize path=_path, latency=_latency, lastEventID=_lastEventID; +- (NSString*) standardizedPath { + return _standardizedPath; +} + - (BOOL) start { @@ -191,7 +196,7 @@ - (NSString*) relativePath { - NSString *base = [watcher.path stringByStandardizingPath]; + NSString *base = watcher.standardizedPath; NSString *standardizedPath = [path stringByStandardizingPath]; if( ! [standardizedPath hasPrefix: base] ) return nil;