On Monday, 14 March 2022 at 09:40:00 UTC, zhad3 wrote:
[...]
I usually compile my projects using LDC where this works fine,
but I don't want to force others to use LDC because of this one
problem.
Hence I'd like to ask on how to change the code so that it
compiles on DMD in release mode (with optimizations). I thought
about having a computational algorithm instead of an encoding
table but sadly I could not find any references in that regard.
Apparently encoding tables seem to be the standard.
OMG, I gasp at my computer screen and waited for minutes. :)
When you edit the code at the back-end level, you can use system
resources in the best way. I think you should start with
[dlang.dmd.backend.aarray](https://github.com/dlang/dmd/blob/master/src/dmd/backend/aarray.d)
If we use the following codes with Ali's code by separate the
keys and values, it compiles fast on DMD and works correctly:
```d
import std.stdio;
import dmd.backend.aarray;
import zencoding.windows949;
struct Make_CP949Table(T)
{
private AArray!(Tinfo!T, T) aa;
this(T[] keys, T[] values)
{
foreach (i, T value; values)
{
T * set = aa.get(&keys[i]);
*set = value;
}
aa.rehash();
}
T* opBinaryRight(string op)(T index)
if (op == "in")
{
T* key = aa.get(&index);
if(*key > 0) return key;
return null;
}
T get(T key)
{
return *aa.get(&key);
}
size_t length()
{
return aa.nodes;
}
}
Make_CP949Table!ushort cp949_table;
shared static this() { cp949_table = Make_CP949Table!ushort(keys,
values); }
// Ali had already prepared these for you ----------------^
void main()
{
const(ubyte[]) cp949 = [
0x64, 0x61, 0x74, 0x61, 0x5C, 0x69, 0x6D, 0x66,
0x5C, 0xB1, 0xB8, 0xC6, 0xE4, 0xC4, 0xDA, 0x5F,
0xC5, 0xA9, 0xB7, 0xE7, 0xBC, 0xBC, 0xC0, 0xCC,
0xB4, 0xF5, 0x5F, 0xB3, 0xB2, 0x2E, 0x69, 0x6D,
0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00];
const(ushort[]) utf16 = [
0x64, 0x61, 0x74, 0x61, 0x5C, 0x69, 0x6D, 0x66,
0x5C, 0xAD6C, 0xD398, 0xCF54, 0x5F, 0xD06C, 0xB8E8,
0xC138,
0xC774, 0xB354, 0x5F, 0xB0A8, 0x2E, 0x69, 0x6D, 0x66];
cp949.fromWindows949.writeln; // data\imf\구페코_크루세이더_남.imf
}
```
SDB@79