-
Notifications
You must be signed in to change notification settings - Fork 715
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
Take some steps toward eliminating the last unsafe
in ring::polyfill
#1732
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright 2023 Brian Smith. | ||
// | ||
// Permission to use, copy, modify, and/or distribute this software for any | ||
// purpose with or without fee is hereby granted, provided that the above | ||
// copyright notice and this permission notice appear in all copies. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES | ||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY | ||
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
|
||
pub trait ArraySplitMap<I, O, const CN: usize, const ON: usize> { | ||
fn array_split_map(self, f: impl Fn([I; CN]) -> O) -> [O; ON]; | ||
} | ||
|
||
impl<I, O> ArraySplitMap<I, O, 4, 3> for [I; 12] { | ||
#[inline] | ||
fn array_split_map(self, f: impl Fn([I; 4]) -> O) -> [O; 3] { | ||
let [a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3] = self; | ||
[ | ||
f([a0, a1, a2, a3]), | ||
f([b0, b1, b2, b3]), | ||
f([c0, c1, c2, c3]), | ||
] | ||
} | ||
} | ||
|
||
impl<I, O> ArraySplitMap<I, O, 4, 4> for [I; 16] { | ||
#[inline] | ||
fn array_split_map(self, f: impl Fn([I; 4]) -> O) -> [O; 4] { | ||
let [a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3, d0, d1, d2, d3] = self; | ||
[ | ||
f([a0, a1, a2, a3]), | ||
f([b0, b1, b2, b3]), | ||
f([c0, c1, c2, c3]), | ||
f([d0, d1, d2, d3]), | ||
] | ||
} | ||
} | ||
|
||
impl<I, O> ArraySplitMap<I, O, 4, 8> for [I; 32] { | ||
#[inline] | ||
fn array_split_map(self, f: impl Fn([I; 4]) -> O) -> [O; 8] { | ||
let [a0, a1, a2, a3, b0, b1, b2, b3, c0, c1, c2, c3, d0, d1, d2, d3, e0, e1, e2, e3, f0, f1, f2, f3, g0, g1, g2, g3, h0, h1, h2, h3] = | ||
self; | ||
[ | ||
f([a0, a1, a2, a3]), | ||
f([b0, b1, b2, b3]), | ||
f([c0, c1, c2, c3]), | ||
f([d0, d1, d2, d3]), | ||
f([e0, e1, e2, e3]), | ||
f([f0, f1, f2, f3]), | ||
f([g0, g1, g2, g3]), | ||
f([h0, h1, h2, h3]), | ||
] | ||
} | ||
} | ||
|
||
impl<I, O> ArraySplitMap<I, O, 8, 2> for [I; 16] { | ||
#[inline] | ||
fn array_split_map(self, f: impl Fn([I; 8]) -> O) -> [O; 2] { | ||
let [a0, a1, a2, a3, a4, a5, a6, a7, b0, b1, b2, b3, b4, b5, b6, b7] = self; | ||
[ | ||
f([a0, a1, a2, a3, a4, a5, a6, a7]), | ||
f([b0, b1, b2, b3, b4, b5, b6, b7]), | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the small arrays that are converted here (the ones for which lines are removed above) this approach seems to optimize well. For the other two larger array sizes (mentioned below), I will post a separate PR that uses different techniques.