-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add concatenation operations to Slice #10157
Comments
Here's an example of |
@watzon your implementation does not work for unions: a = Bytes[1, 2, 3, 4]
b = Slice[5, 6, 7, 8]
c = Bytes[9, 10, 11, 12]
puts Slice(Int32 | UInt8).concat(a, b, c)
puts a + b As @Blacksmoke16 suggested, |
|
It is possible, because it works for |
|
Speaking of
If we define additionally |
This is a reopening of the conversation from #5826 to see if minds may have changed. Currently it's not possible to concatenate slices, with the rationale being "we have IO for that". However there are some cases where that could add several lines to a function and actually make it harder to understand what's going on. Take this example:
I know it's a long example, but it's a real one. And a common one when it comes to dealing with cryptography. With slice concatenation it becomes so much simpler:
I feel like the second example is a bit easier to follow, and since a
Slice(T)#+
operation would likely be using memcpy operations under the hood I'd imagine it would be faster too (though I could definitely be wrong). This would also be super trivial to add.Yes, it returns a new Slice, just like
Array(T)#+
returns a new Array. For more performance when concatenating it would also be nice to have aSlice(T)#concat
method which would do basically the same thing, but only create one intermediary slice. The+
method could then just use that.The text was updated successfully, but these errors were encountered: