From 95dd118190cd2c16cbe7bcbd25a1bdb42977ede3 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 10 Jun 2008 11:58:11 -0400 Subject: [PATCH] Rewrite BreakpointManager to use NSArray instead a faux hashtable using a NSDictionary * Source/Breakpoint.m+h --- Source/BreakpointManager.h | 5 ++-- Source/BreakpointManager.m | 54 ++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/Source/BreakpointManager.h b/Source/BreakpointManager.h index da8cc03..33f94cf 100644 --- a/Source/BreakpointManager.h +++ b/Source/BreakpointManager.h @@ -19,13 +19,14 @@ @interface BreakpointManager : NSObject { - NSMutableDictionary *breakpoints; + NSMutableArray *breakpoints; } + (BreakpointManager *)sharedManager; +- (NSArray *)breakpoints; - (void)addBreakpoint:(Breakpoint *)bp; - (Breakpoint *)removeBreakpointAt:(int)line inFile:(NSString *)file; -- (NSSet *)breakpointsForFile:(NSString *)file; +- (NSArray *)breakpointsForFile:(NSString *)file; - (BOOL)hasBreakpointAt:(int)line inFile:(NSString *)file; @end diff --git a/Source/BreakpointManager.m b/Source/BreakpointManager.m index b1a1f16..1931a09 100644 --- a/Source/BreakpointManager.m +++ b/Source/BreakpointManager.m @@ -27,7 +27,7 @@ { if (!breakpoints) { - breakpoints = [[NSMutableDictionary alloc] init]; + breakpoints = [[NSMutableArray alloc] init]; } } return self; @@ -46,20 +46,22 @@ return manager; } +/** + * Returns an array of all the breakpoints + */ +- (NSArray *)breakpoints +{ + return breakpoints; +} + /** * Registers a breakpoint at a given line */ - (void)addBreakpoint:(Breakpoint *)bp; { - NSMutableSet *lines = [breakpoints valueForKey:[bp file]]; - if (lines == nil) + if (![breakpoints containsObject:bp]) { - lines = [NSMutableSet setWithObject:bp]; - [breakpoints setValue:lines forKey:[bp file]]; - } - else - { - [lines addObject:bp]; + [breakpoints addObject:bp]; } } @@ -68,12 +70,11 @@ */ - (Breakpoint *)removeBreakpointAt:(int)line inFile:(NSString *)file { - NSMutableSet *lines = [breakpoints valueForKey:file]; - for (Breakpoint *b in lines) + for (Breakpoint *b in breakpoints) { - if ([b line] == line) + if ([b line] == line && [[b file] isEqualToString:file]) { - [lines removeObject:b]; + [breakpoints removeObject:b]; return b; } } @@ -83,9 +84,18 @@ /** * Returns all the breakpoints for a given file */ -- (NSSet *)breakpointsForFile:(NSString *)file +- (NSArray *)breakpointsForFile:(NSString *)file { - return [breakpoints valueForKey:file]; + NSMutableArray *matches = [NSMutableArray array]; + for (Breakpoint *b in breakpoints) + { + if ([[b file] isEqualToString:file]) + { + [matches addObject:b]; + } + } + + return matches; } /** @@ -93,19 +103,7 @@ */ - (BOOL)hasBreakpointAt:(int)line inFile:(NSString *)file { - NSSet *lines = [breakpoints valueForKey:file]; - if (!lines) - { - return NO; - } - for (Breakpoint *b in lines) - { - if ([b line] == line) - { - return YES; - } - } - return NO; + return [breakpoints containsObject:[[Breakpoint alloc] initWithLine:line inFile:file]]; } @end -- 2.43.5