Compilation of lengthy C++ Files

David Brown david@westcontrol.com
Thu Oct 19 16:03:35 GMT 2023


On 19/10/2023 17:11, Kai Song via Gcc-help wrote:

(It can be helpful to include attributions when replying, so that it is 
clear who wrote what.  Thus you should have this line included:)

 > On 19/10/2023 16:26, Jonathan Wakely via Gcc-help wrote:


>> Nothing you have said actually explains why you can't refactor the
>> code into utility functions that avoid doing everything in one huge
>> function.
>>
> 
> Because there are no two pieces of code that are exactly identical. The
> relative distance of two variables being involved into an identical formula
> will change with every line.
> Example:
> Line 1000: tmp[100]=foo(tmp[101],tmp[102]);
> Line 2000: tmp[200]=foo(tmp[201],tmp[203]); // dang it, not tmp[202] but
> tmp[203]
> It is like with penrose tiling. It seems all identical but the details
> break it. You just do not find two identical local areas. No-where. And if,
> you have to particularly search for them by brute-force, and that should
> become useless whenever the particular pattern you try to find does just
> not exist in that particular user's instance.
> 

Surely this is screaming out for a table?

const int foo_table[][3] = {
     { 100, 101, 102 },
     { 200, 201, 203 },
	...
};


	for (int i = 0; i < 100000000; i++) {
		tmp[foo_table[i][0]] =
			foo(tmp[foo_table[i][1]], tmp[foo_table[i][2]]);
	}

This will turn your million-line program into a four line program with a 
big table, which will compile quickly and run faster.





More information about the Gcc-help mailing list