-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't perform swap when src == dst. #5041
- Loading branch information
Showing
2 changed files
with
67 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Issue #5041 - avoid overlapping memcpy when src and dest of a swap are the same | ||
|
||
pub fn main() { | ||
let mut test = TestDescAndFn { | ||
desc: TestDesc { | ||
name: DynTestName(~"test"), | ||
should_fail: false | ||
}, | ||
testfn: DynTestFn(|| ()), | ||
}; | ||
do_swap(&mut test); | ||
} | ||
|
||
fn do_swap(test: &mut TestDescAndFn) { | ||
*test <-> *test; | ||
} | ||
|
||
pub enum TestName { | ||
DynTestName(~str) | ||
} | ||
|
||
pub enum TestFn { | ||
DynTestFn(~fn()), | ||
DynBenchFn(~fn(&mut int)) | ||
} | ||
|
||
pub struct TestDesc { | ||
name: TestName, | ||
should_fail: bool | ||
} | ||
|
||
pub struct TestDescAndFn { | ||
desc: TestDesc, | ||
testfn: TestFn, | ||
} |
423843e
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.
saw approval from brson
at brson@423843e
423843e
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.
merging brson/rust/swap = 423843e into auto
423843e
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.
brson/rust/swap = 423843e merged ok, testing candidate = 8f8f0ec
423843e
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.
all tests pass:
http://buildbot.rust-lang.org/builders/auto-linux/builds/202
http://buildbot.rust-lang.org/builders/auto-win/builds/197
http://buildbot.rust-lang.org/builders/auto-mac/builds/206
423843e
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.
fast-forwarding incoming to auto = 8f8f0ec