[Toybox] [CLEANUP] stat's done.

Rob Landley rob at landley.net
Sun Jun 2 13:34:06 PDT 2013


I put description text into commits 912, 914, 916, and 917, all  
building on Felix's work. And then the actual mv was its own commit  
(918) in hopes of confusing source control less. (Although I did switch  
"default n" to "default y" in the same commit so the file wasn't  
_identical_...)

   http://landley.net/hg/toybox/rev/912
   http://landley.net/hg/toybox/rev/914
   http://landley.net/hg/toybox/rev/916
   http://landley.net/hg/toybox/rev/917

I was thinking of doing some variant of the table-driven logic I've  
been building in ifconfig's main (which is why I checked in the  
peek/poke stuff), but each iteration here is just a single function  
call with two arguments, so it's not really a win.

Instead I collapsed the big switch/case things into if/else staircases,  
which is a slightly nonobvious move but makes the code easier to  
understand (at least for me) because it fits 4 times as much code on  
the screen.

The 4 lines were Blank line, case line, xprintf(), break. This was  
replaced with 1 line: "if (test) xprintf();". So the redundancy I'm  
eliminating is 3 of the 4 repeated source lines. (It's possible for a  
refactor to complicate things and thus make it harder to understand,  
but it's not the case here.)

This doesn't even really make the binary bigger. (I haven't done a  
bloatcheck on it this time but previous such switches I found it  
actually made it smaller: the switch/case is often a binary search on a  
lookup on a table which is optimized for speed not size, the if/else  
can cache half the comparison in a register. As for speed, if it's all  
fitting in L1 cache it's a rounding error, the function call pulling in  
a new cache line is a bigger deal in performance terms and we don't  
worry about that...)

Rob
 1370205246.0


More information about the Toybox mailing list