3 ms·
Pike says the code is in assembler - which means it is written by hand. In assembler `name[0]=='.'` is simple to write. Fetch what name points to and compare
by soegaard 4y ago
Pike says the code is in assembler - which means it is written by hand.
In assembler `name[0]=='.'` is simple to write. Fetch what name points to
and compare it to a literal `'.'`.
A function call on the other hand requires pushing registers to the stack,
pushing the arguments to the stack, call the function, and then restoring the registers.
So if you are in a hurry and just want to try something, you will write the equivalent to `name[0]=='.'`.
- samatman 4y agoIt could have checked for ".\0" and "..\0", is the thing. There was no need to bring the whole of strcmp to bear. I think hiding files with a path convention is Good, Actually, but I'm comfortable being in the minority on that, and it's possible that if we instead had a hidden flag a la chmod permissions I would prefer that.
- Findecanor 4y agoI think dotfiles is the best convention I've seen for hidden files. With "hidden" being a file attribute (like on MS-DOS), you'd have the risk of a filename collision with a file that you don't know is there.
- jerf 4y agoAlso, I mean, if you've grown up in the era of multicore gigahertz, where "gigabytes" is where our opening bid on RAM starts, you just don't understand what programming on this era of machine was like. The difference between a single name[0]=='.' and two calls to a string comparison function could very well have resulted in noticeable differences in performance, in real-world cases. I like to keep an eye on the costs of what code I'm writing to make sure I don't get too 21st century and let my codebase bloat until it's slow as molasses, but at the same time I happily harvest the benefits of usually not caring whether this function call is inlined or not, or caring about the exact number of cycles an indirect function call takes, etc. It's a delicate balance but worthwhile to cultivate it.
- slowhand09 4y agoditto! Having coded on PDP-1170s and limited to 32K, fighting with link maps, planning common segments etc... We scratched for bytes.