Category Archives: Programming
Time Machine Menu
The Time Machine application, when in the dock, enables access to functions for showing Time Machine, backing up now, stopping an existing backup, browsing other Time Machine disks and showing Time Machine preferences. If you’re like me, you’d like access to these features without the app in the dock; unfortunately, you can’t — by default. I’ve done a bit of digging and was able to implement all but one of these features in a menu extra. Download it and the … Continue reading
Pointless Optimization
The other day I needed to write a function to give me a formatted string representation of a quantity of bytes. Pretty trivial function, but nontheless, I found myself optimizing it. I ended up with the following: static uint64_t count = 7; static NSString *suffixes[7] = { @"B", @"KiB", @"MiB", @"GiB", @"TiB", @"PiB", @"EiB"}; uint64_t i, c; for (i = 1024, c = 0; i < (count << 60); i <<= 10, c++) { if (bytes < i) return [NSString … Continue reading
Color Setting Performance
If you’re looking to eek some extra performance out of your drawing code, take a look at how you’re setting your fill and stroke colors. Setting the color using CGContextSetRGBFillColor() or creating a new CGColorRef/NSColor object each time you set the color is quite expensive to do each time you draw. Depending on how many colors you use in your drawing, consider caching the CGColorRef objects and using CGContextSetFillColorWithColor() or -[NSColor setFill] instead. A CGColorRef is 48 bytes for a … Continue reading