Use linear file list in FInput.TInputFileManager instead of linked.
Not sure if TInputFile.ref_index
can ever be non-sequential, I tried to compile my application and the compiler and didn’t see counterexamples.
First, linear list is simpler to work with, and this patch saves 35 lines of code.
Second, there is a quadratic traversal in FPPU.TPPUModule.WriteSourceFiles
against which an artificial example can be trivially built: when compiling main.pas
from many_includes.7z on my computer, unpatched FPPU.TPPUModule.WriteSourceFiles
takes 150 ms and patched takes 70 ms. See this article, sections “O(n^2) is usually not okay” and “Actually, the worst is pretty bad”.
Backstory is that I tried to tinker with finput.pas
because I like to include one file many times and the compiler constantly reopens and rereads them, so I got an 1% speedup when compiling my application with a 64 Kb LRU file data cache. But results were much more modest when compiling the compiler, so I wouldn’t be able to convince you to do that.