Skip to content

Comments

Use __traits(isSame) for min,maxElement#6144

Merged
dlang-bot merged 2 commits intodlang:masterfrom
wilzbach:traits-is-same-min-max
Mar 16, 2018
Merged

Use __traits(isSame) for min,maxElement#6144
dlang-bot merged 2 commits intodlang:masterfrom
wilzbach:traits-is-same-min-max

Conversation

@wilzbach
Copy link
Contributor

@wilzbach wilzbach commented Feb 8, 2018

__traits(isSame, a, b) rocks :)

The specialization was discussed in #4265 and merged in #5001.

Use https://github.com/dlang/phobos/pull/6144/files?w=1 for a nicer diff.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @wilzbach!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

{
foreach (const i; 0 .. r.length)

// direct access via a random access range is faster
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really true? Looping over an index is faster than repeated empty/front/popFront()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, D ranges have an overhead of ~20-50% for arrays. It's pretty bad for e.g. joiner (see https://gist.github.com/wilzbach/ffd5d20639766a831fd4b1962572897a), but it's a problem here too.

Check also #4265

The reason is that the compiler can inline the commands a lot better for native arrays and even do vectorization better than for the generic loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants