d的静态数组与dmd

import std.array;

extern (C) void main() {
  auto numbersINeed = staticArray([1, 2, 3, 4, 5]);

  import std.range;
  import std.algorithm;
  import core.stdc.stdio;

  //          |
  //          V
  numbersINeed[].each!(n => printf("%d ", n));
//静态数组用区间算法.
}

[]切换元素,来减小大小.

DMD可内联,

int example.foo(immutable(char)[]):
        cmp     rdi, 5
        jne     .LBB0_3
        mov     eax, 1764586337
        xor     eax, dword ptr [rsi]
        movzx   ecx, byte ptr [rsi + 4]
        xor     ecx, 115
        or      ecx, eax
        je      .LBB0_2
.LBB0_3:
        mov     eax, 100
        ret
.LBB0_2:
        mov     eax, 200
        ret

dmd可以内联λ,底层没问题,只是优化包含许多特例,而dmd没有罢了.非通用优化分析数据流,而dmd都有.

posted @ 2022-06-07 09:56  zjh6  阅读(17)  评论(0)    收藏  举报  来源