struct Location size
Walter Bright
newshound2 at digitalmars.com
Tue May 9 00:24:44 UTC 2023
This PR https://github.com/dlang/dmd/pull/15199 reduces its size by 8 bytes,
resulting in about 20Mb of memory savings compiling druntime, according to @dkorpel.
It is currently:
struct Loc
{
uint linnum; // line number, starting from 1
ushort charnum; // utf8 code unit index relative to start of line, starting
from 1
ushort fileIndex; // index into filenames[], starting from 1 (0 means no
filename)
}
which is 8 bytes.
If it was 4 bytes, it could still store 4 billion unique locations, which ought
to be enough for everyone. I toyed around with various encodings:
6 bits for column - 1..64
15 bits for line - 1..32768
11 bits for file - 2047
I also thought of schemes like having the sign bit set an alternate encoding scheme.
So, for great glory, can anyone come up with a clever scheme that uses only 32 bits?
More information about the Digitalmars-d
mailing list