Skip to content

Make std.algo.copy CTFE-able#5282

Merged
dlang-bot merged 1 commit intodlang:masterfrom
DmitryOlshansky:ctfe-copy
Mar 16, 2017
Merged

Make std.algo.copy CTFE-able#5282
dlang-bot merged 1 commit intodlang:masterfrom
DmitryOlshansky:ctfe-copy

Conversation

@DmitryOlshansky
Copy link
Member

No description provided.

Copy link
Member

@quickfur quickfur left a comment

Choose a reason for hiding this comment

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

Nice! I like it.

Will defer to another reviewer to approve, though. Just in case I missed something important.

@JackStouffer
Copy link
Contributor

Why use the first branch when the second one is also CTFE-able and supposedly faster?

@JackStouffer
Copy link
Contributor

JackStouffer commented Mar 16, 2017

int[] func(int[] source, int[] target) {
    const tlen = target.length;
    const slen = source.length;
    target[0 .. slen] = source[];
    return target[slen .. $];
}

void main()
{
	enum a = func([1, 2, 3], [4, 5, 6, 7]);
	pragma(msg, a);
}

works and gives the right answer

@DmitryOlshansky
Copy link
Member Author

Why use the first branch when the second one is also CTFE-able and supposedly faster?

Because we can't guarantee there is no overlap between the arrays. Secondly I highly doubt that CTFE actually does things such as memcpy which is what the fast path tries to get.

@dlang-bot dlang-bot merged commit ef8e175 into dlang:master Mar 16, 2017
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