On Mon, 01 Sep 2014 09:22:50 +0000 bearophile via Digitalmars-d-learn <[email protected]> wrote:
> In theory the best solution is to improve the performance of the
> "byKey.front" and "byValue.front" idioms.
i found that slowdown is from _aaRange(), not from delegates.
the following code is slow even w/o delegate creation:
import core.stdc.stdio;
ref K firstKey(T : V[K], V, K)(T aa) @property
{
return *cast(K*)_aaRangeFrontKey(_aaRange(cast(void*)aa));
}
ref V firstVal(T : V[K], V, K)(T aa) @property
{
return *cast(V*)_aaRangeFrontValue(_aaRange(cast(void*)aa));
}
int main() {
long[int] aa;
for (int i = 0; i < 50000; i++)
aa[i] = i;
long total = 0;
while (aa.length) {
//int k = aa.byKey.front;
int k = aa.firstKey;
//long v = aa.byValue.front;
long v = aa.firstVal;
aa.remove(k);
total += k + v;
}
printf("%lld\n", total);
return 0;
}
seems that we need two more hooks for AAs: `_aaFrontKey()` and
`_aaFrontValue()`.
> x.pop() sounds nicer :-)
ah, sure. i'm not very good in inventing names. ;-)
signature.asc
Description: PGP signature
