Guest User

Untitled

a guest
Jun 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #[inline(never)]
  2. fn eat(u: u8) {
  3. println!("{}", u);
  4. }
  5.  
  6. #[inline(never)]
  7. fn foo(args: &[u8]) {
  8. for i in args {
  9. eat(*i);
  10. }
  11. }
  12.  
  13. #[inline(never)]
  14. fn foo2(args: &[u8]) {
  15. unsafe {
  16. let y = args.as_ptr().offset(args.len() as isize);
  17. let mut x = args.as_ptr();
  18. while (x != y) {
  19. eat(*x);
  20. x = x.offset(1);
  21. }
  22. }
  23. }
  24.  
  25. #[inline(never)]
  26. fn produce() -> Box<Vec<u8>> {
  27. /* Busywork so compiler does not inline shit */
  28. let scores = [7, 8, 9, 10, 11, 12, 13, 14, 15];
  29. let mut v = Box::new(Vec::new());
  30. {
  31. v.extend_from_slice(&scores);
  32. }
  33. v
  34. }
  35.  
  36. fn main() {
  37.  
  38. // busywork to break inlining
  39. let x = produce();
  40. foo(x.as_slice());
  41. foo2(x.as_slice());
  42. }
Add Comment
Please, Sign In to add comment