-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lukas Markeffsky
committed
Jan 17, 2024
1 parent
d0dfd3c
commit 63ce0c8
Showing
1 changed file
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Check that draining at the front or back doesn't copy memory. | ||
|
||
// compile-flags: -O | ||
// ignore-debug: the debug assertions get in the way | ||
|
||
#![crate_type = "lib"] | ||
|
||
use std::collections::VecDeque; | ||
|
||
// CHECK-LABEL: @clear | ||
// CHECK-NOT: call | ||
// CHECK-NOT: br | ||
// CHECK: getelementptr inbounds | ||
// CHECK-NEXT: call void @llvm.memset | ||
// CHECK-NEXT: ret void | ||
#[no_mangle] | ||
pub fn clear(v: &mut VecDeque<i32>) { | ||
v.drain(..); | ||
} | ||
|
||
// CHECK-LABEL: @truncate | ||
// CHECK-NOT: call | ||
// CHECK: br | ||
// CHECK-NOT: call | ||
// CHECK: br | ||
// CHECK-NOT: call | ||
// CHECK: br | ||
// CHECK-NOT: call | ||
// CHECK: br | ||
// CHECK-NOT: call | ||
// CHECK-NOT: br | ||
// CHECK: ret void | ||
#[no_mangle] | ||
pub fn truncate(v: &mut VecDeque<i32>, n: usize) { | ||
if n < v.len() { | ||
v.drain(n..); | ||
} | ||
} | ||
|
||
// CHECK-LABEL: @advance | ||
// CHECK-NOT: call | ||
// CHECK: br | ||
// CHECK-NOT: call | ||
// CHECK: br | ||
// CHECK-NOT: call | ||
// CHECK: br | ||
// CHECK-NOT: call | ||
// CHECK: br | ||
// CHECK-NOT: call | ||
// CHECK: br | ||
// CHECK-NOT: call | ||
// CHECK-NOT: br | ||
// CHECK: ret void | ||
#[no_mangle] | ||
pub fn advance(v: &mut VecDeque<i32>, n: usize) { | ||
if n < v.len() { | ||
v.drain(..n); | ||
} else { | ||
v.clear(); | ||
} | ||
} | ||
|
||
// CHECK-LABEL: @remove | ||
// CHECK: call | ||
#[no_mangle] | ||
pub fn remove(v: &mut VecDeque<i32>, a: usize, b: usize) { | ||
v.drain(a..b); | ||
} |