3 ms·
An alternative C version (Ted's is in Go) is described in the last link of the article [1]. That is a rather interesting tutorial for how to write high-performi
by unwind 4y ago
An alternative C version (Ted's is in Go) is described in the last link of the article [1]. That is a rather interesting tutorial for how to write high-performing tools of this kind, it deals with stuff like string interning/buffering, pre-allocating "objects" to avoid having to implement dynamically growing data structures, and so on.
It's pretty cool how the author uses LLVM as an example of a big codebase, then uses "10X that" as the requirement for how many directories and so on to support.
[1]: https://nullprogram.com/blog/2022/05/22/ https://nullprogram.com/blog/2022/05/22/
- skanga 4y agoIs this only for c code? I ran it on a Java codebase and got 0LOC 0B on all dirs
- js2 4y agoYes: https://github.com/skeeto/scratch/blob/5129fd45153999924334c5a989216e98cb5e1098/misc/watc.c#L111 https://github.com/skeeto/scratch/blob/5129fd45153999924334c...
- unwind 4y agoOMG that is so ... I don't even know. Is it over-engineering to use a static 16-entry perfect hash of file name extensions to filter out the five supported languages? It's at least somewhat obscure, in the sense that adding support for another language becomes quite involved. It would be interesting to micro-bench this code against something more naïve that just strcmp()s the extension against a list of known strings, or something.
- js2 4y ago> Is it over-engineering to use a static 16-entry perfect hash of file name extensions to filter out the five supported languages? It's patently absurd. I also like the ATOMIC_RADD for populating the line count: https://github.com/skeeto/scratch/blob/5129fd45153999924334c5a989216e98cb5e1098/misc/watc.c#L210 https://github.com/skeeto/scratch/blob/5129fd45153999924334c... This entire program is too clever by half, while still not doing a "correct" source line count (it just counts new lines).