]> granicus.if.org Git - transmission/commitdiff
only lock focus and redraw the pieces view if it has been updated
authorMitchell Livingston <livings124@transmissionbt.com>
Tue, 10 Jun 2008 21:46:34 +0000 (21:46 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Tue, 10 Jun 2008 21:46:34 +0000 (21:46 +0000)
macosx/PiecesView.m

index 01a87a09aa380b4afd239e883c2f0afba9db34c6..ad54f0c598b5be364b979cd8d950305219b5a522 100644 (file)
         [fTorrent getAmountFinished: piecesPercent size: fNumPieces];
     }
     
+    NSImage * image = [self image];
+    
     int i, j, index = -1;
     NSRect rect = NSMakeRect(0, 0, fWidth, fWidth);
-    
-    NSImage * image = [self image];
-    [image lockFocus];
+    BOOL change = NO;
     
     for (i = 0; i < fAcross; i++)
         for (j = 0; j < fAcross; j++)
             
             if (pieceColor)
             {
+                //avoid unneeded memory usage by only locking focus if drawing will occur
+                if (!change)
+                {
+                    change = YES;
+                    [image lockFocus];
+                }
+                
                 rect.origin = NSMakePoint(j * (fWidth + BETWEEN) + BETWEEN + fExtraBorder,
                                         [image size].width - (i + 1) * (fWidth + BETWEEN) - fExtraBorder);
                 
             }
         }
     
-    [image unlockFocus];
-    [self setNeedsDisplay];
+    if (change)
+    {
+        [image unlockFocus];
+        [self setNeedsDisplay];
+    }
     
     tr_free(pieces);
     tr_free(piecesPercent);