Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4aa43c7

Browse files
committed
Auto merge ofrust-lang#125720 - folkertdev:optimize_for_size-ptr-rotate, r=Amanieu
make `ptr::rotate` smaller when using `optimize_for_size`code to reproducehttps://github.com/folkertdev/optimize_for_size-slice-rotateIn the example the size of `.text` goes down from 1624 to 276 bytes.```> cargo size --release --features "left-std" -- -Aslice-rotate :section size addr.vector_table 1024 0x0.text 1624 0x400.rodata 0 0xa58.data 0 0x20000000.gnu.sgstubs 0 0xa60.bss 0 0x20000000.uninit 0 0x20000000.debug_loc 591 0x0.debug_abbrev 1452 0x0.debug_info 10634 0x0.debug_aranges 480 0x0.debug_ranges 1504 0x0.debug_str 11716 0x0.comment 72 0x0.ARM.attributes 56 0x0.debug_frame 1036 0x0.debug_line 5837 0x0Total 36026> cargo size --release --features "left-size" -- -Aslice-rotate :section size addr.vector_table 1024 0x0.text 276 0x400.rodata 0 0x514.data 0 0x20000000.gnu.sgstubs 0 0x520.bss 0 0x20000000.uninit 0 0x20000000.debug_loc 347 0x0.debug_abbrev 965 0x0.debug_info 4216 0x0.debug_aranges 168 0x0.debug_ranges 216 0x0.debug_str 3615 0x0.comment 72 0x0.ARM.attributes 56 0x0.debug_frame 232 0x0.debug_line 723 0x0Total 11910```tracking issue:rust-lang#125612
2 parents89b5784 +1265244 commit4aa43c7

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

‎core/src/slice/rotate.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ pub unsafe fn ptr_rotate<T>(mut left: usize, mut mid: *mut T, mut right: usize)
7171
if(right ==0) ||(left ==0){
7272
return;
7373
}
74-
if(left + right <24) ||(mem::size_of::<T>() > mem::size_of::<[usize;4]>()){
74+
if !cfg!(feature ="optimize_for_size")
75+
&&((left + right <24) ||(mem::size_of::<T>() > mem::size_of::<[usize;4]>()))
76+
{
7577
// Algorithm 1
7678
// Microbenchmarks indicate that the average performance for random shifts is better all
7779
// the way until about `left + right == 32`, but the worst case performance breaks even
@@ -158,7 +160,9 @@ pub unsafe fn ptr_rotate<T>(mut left: usize, mut mid: *mut T, mut right: usize)
158160
}
159161
return;
160162
// `T` is not a zero-sized type, so it's okay to divide by its size.
161-
}elseif cmp::min(left, right) <= mem::size_of::<BufType>() / mem::size_of::<T>(){
163+
}elseif !cfg!(feature ="optimize_for_size")
164+
&& cmp::min(left, right) <= mem::size_of::<BufType>() / mem::size_of::<T>()
165+
{
162166
// Algorithm 2
163167
// The `[T; 0]` here is to ensure this is appropriately aligned for T
164168
letmut rawarray =MaybeUninit::<(BufType,[T;0])>::uninit();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp