From 5daf717b3e204521f12d736a349ec55ea58fa52e Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 2 Dec 2016 08:34:32 -0500 Subject: [PATCH] Make BSSourceView.markers be a set of line numbers, rather than Breakpoint*. --- Source/BSLineNumberRulerView.mm | 6 ++---- Source/BSSourceView.h | 6 +++--- Source/BreakpointController.m | 4 ++-- Source/BreakpointManager.h | 2 +- Source/BreakpointManager.m | 22 ++++++++++++---------- Source/DebuggerController.m | 5 ++--- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Source/BSLineNumberRulerView.mm b/Source/BSLineNumberRulerView.mm index 969e44f..bfe0eba 100644 --- a/Source/BSLineNumberRulerView.mm +++ b/Source/BSLineNumberRulerView.mm @@ -87,7 +87,7 @@ const CGFloat kRulerRightPadding = 2.5; // Load any markers. The superview takes care of filtering out for just the // curently displayed file. - NSSet* markers = [sourceView_ markers]; + NSSet* markers = [sourceView_ markers]; // Go through the lines. const NSRange kNullRange = NSMakeRange(NSNotFound, 0); @@ -127,9 +127,7 @@ const CGFloat kRulerRightPadding = 2.5; // ruler, rather than just the width of the string. drawRect.origin.x = NSMinX(rect); - Breakpoint* test = [[[Breakpoint alloc] initWithLine:lineNumber - inFile:[sourceView_ file]] autorelease]; - if ([markers containsObject:test]) { + if ([markers containsObject:@(lineNumber)]) { [self drawBreakpointInRect:drawRect]; } if (sourceView_.markedLine == lineNumber) { diff --git a/Source/BSSourceView.h b/Source/BSSourceView.h index c310113..b940289 100644 --- a/Source/BSSourceView.h +++ b/Source/BSSourceView.h @@ -32,8 +32,8 @@ BSLineNumberRulerView* ruler_; NSScrollView* scrollView_; - // Set of Breakpoint objects. - NSSet* markers_; + // Line numbers to mark. + NSSet* markers_; NSString* file_; NSUInteger markedLine_; @@ -43,7 +43,7 @@ @property (nonatomic, readonly) NSTextView* textView; @property (nonatomic, readonly) NSScrollView* scrollView; -@property (nonatomic, retain) NSSet* markers; +@property (nonatomic, retain) NSSet* markers; @property (nonatomic, assign) NSString* file; @property (nonatomic, assign) NSUInteger markedLine; @property (nonatomic, assign) id delegate; diff --git a/Source/BreakpointController.m b/Source/BreakpointController.m index 3f61811..1b71ce2 100644 --- a/Source/BreakpointController.m +++ b/Source/BreakpointController.m @@ -85,7 +85,7 @@ Breakpoint* bp = [selection objectAtIndex:0]; [sourceView setFile:[bp file]]; [sourceView scrollToLine:[bp line]]; - [sourceView setMarkers:[NSSet setWithArray:[manager breakpointsForFile:[bp file]]]]; + [sourceView setMarkers:[manager breakpointsForFile:bp.file]]; } #pragma mark BSSourceView Delegate @@ -106,7 +106,7 @@ [bp release]; } - [sourceView setMarkers:[NSSet setWithArray:[manager breakpointsForFile:file]]]; + [sourceView setMarkers:[manager breakpointsForFile:file]]; } /** diff --git a/Source/BreakpointManager.h b/Source/BreakpointManager.h index f553393..438d40b 100644 --- a/Source/BreakpointManager.h +++ b/Source/BreakpointManager.h @@ -32,7 +32,7 @@ + (BreakpointManager*)sharedManager; - (void)addBreakpoint:(Breakpoint*)bp; - (Breakpoint*)removeBreakpointAt:(NSUInteger)line inFile:(NSString*)file; -- (NSArray*)breakpointsForFile:(NSString*)file; +- (NSSet*)breakpointsForFile:(NSString*)file; - (BOOL)hasBreakpointAt:(NSUInteger)line inFile:(NSString*)file; @end diff --git a/Source/BreakpointManager.m b/Source/BreakpointManager.m index 1301ae5..2a3e2c0 100644 --- a/Source/BreakpointManager.m +++ b/Source/BreakpointManager.m @@ -94,6 +94,10 @@ { if ([b line] == line && [[b file] isEqualToString:file]) { + // Keep the breakpoint alive after it is removed from the breakpoints + // array. + [[b retain] autorelease]; + [breakpoints removeObject:b]; [connection removeBreakpoint:b]; @@ -110,17 +114,15 @@ /** * Returns all the breakpoints for a given file */ -- (NSArray*)breakpointsForFile:(NSString*)file +- (NSSet*)breakpointsForFile:(NSString*)file { - NSMutableArray* matches = [NSMutableArray array]; - for (Breakpoint* b in breakpoints) - { - if ([[b file] isEqualToString:file]) - { - [matches addObject:b]; + NSMutableSet* matches = [NSMutableSet set]; + for (Breakpoint* b in breakpoints) { + if ([b.file isEqualToString:file]) { + [matches addObject:@(b.line)]; } } - + return matches; } @@ -143,9 +145,9 @@ AppDelegate* appDel = [NSApp delegate]; [[[appDel breakpoint] arrayController] rearrangeObjects]; [[[appDel breakpoint] sourceView] setNeedsDisplay:YES]; - [[[appDel breakpoint] sourceView] setMarkers:[NSSet setWithArray:[self breakpointsForFile:file]]]; + [[[appDel breakpoint] sourceView] setMarkers:[self breakpointsForFile:file]]; [[[appDel debugger] sourceViewer] setNeedsDisplay:YES]; - [[[appDel debugger] sourceViewer] setMarkers:[NSSet setWithArray:[self breakpointsForFile:file]]]; + [[[appDel debugger] sourceViewer] setMarkers:[self breakpointsForFile:file]]; } @end diff --git a/Source/DebuggerController.m b/Source/DebuggerController.m index e09833d..352eecb 100644 --- a/Source/DebuggerController.m +++ b/Source/DebuggerController.m @@ -351,7 +351,7 @@ { [sourceViewer setString:frame.source asFile:filename]; - NSSet* breakpoints = [NSSet setWithArray:[[BreakpointManager sharedManager] breakpointsForFile:filename]]; + NSSet* breakpoints = [[BreakpointManager sharedManager] breakpointsForFile:filename]; [sourceViewer setMarkers:breakpoints]; } @@ -419,8 +419,7 @@ [bp release]; } - [sourceViewer setMarkers:[NSSet setWithArray:[mngr breakpointsForFile:file]]]; - [sourceViewer setNeedsDisplay:YES]; + [sourceViewer setMarkers:[mngr breakpointsForFile:file]]; } @end -- 2.43.5