Skip to content

Instantly share code, notes, and snippets.

@bluss
Created November 27, 2016 15:53
Show Gist options
  • Select an option

  • Save bluss/61c32daae1bd31d9d7605983df3ace5f to your computer and use it in GitHub Desktop.

Select an option

Save bluss/61c32daae1bd31d9d7605983df3ace5f to your computer and use it in GitHub Desktop.
; ModuleID = 'extend_from_slice.cgu-0.rs'
source_filename = "extend_from_slice.cgu-0.rs"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
%str_slice = type { i8*, i64 }
%"test::Bencher" = type { i64, %"std::time::duration::Duration", i64 }
%"std::time::duration::Duration" = type { i64, i32 }
%"std::time::Instant" = type { %"std::sys::imp::time::inner::Instant" }
%"std::sys::imp::time::inner::Instant" = type { %"std::sys::imp::time::Timespec" }
%"std::sys::imp::time::Timespec" = type { %"libc::unix::timespec" }
%"libc::unix::timespec" = type { i64, i64 }
%"test::TestDescAndFn" = type { %"test::TestDesc", %"test::TestFn" }
%"test::TestDesc" = type { %"test::TestName", i8, %"test::ShouldPanic" }
%"test::TestName" = type { i64, [0 x i64], [3 x i64] }
%"test::ShouldPanic" = type { i64, [0 x i64], [2 x i64] }
%"test::TestFn" = type { i64, [0 x i64], [2 x i64] }
%"unwind::libunwind::_Unwind_Exception" = type { i64, void (i32, %"unwind::libunwind::_Unwind_Exception"*)*, [6 x i64] }
%"unwind::libunwind::_Unwind_Context" = type {}
@str.4 = internal constant [13 x i8] c"test_extend_2"
@ref.5 = internal unnamed_addr constant { { { { i64, %str_slice, [8 x i8] }, i1, [7 x i8], { i64, [16 x i8] } }, { i64, void (%"test::Bencher"*)*, [8 x i8] } } } { { { { i64, %str_slice, [8 x i8] }, i1, [7 x i8], { i64, [16 x i8] } }, { i64, void (%"test::Bencher"*)*, [8 x i8] } } { { { i64, %str_slice, [8 x i8] }, i1, [7 x i8], { i64, [16 x i8] } } { { i64, %str_slice, [8 x i8] } { i64 0, %str_slice { i8* getelementptr inbounds ([13 x i8], [13 x i8]* @str.4, i32 0, i32 0), i64 13 }, [8 x i8] undef }, i1 false, [7 x i8] undef, { i64, [16 x i8] } { i64 0, [16 x i8] undef } }, { i64, void (%"test::Bencher"*)*, [8 x i8] } { i64 1, void (%"test::Bencher"*)* @_ZN17extend_from_slice13test_extend_217hf0b9fd26aa755952E, [8 x i8] undef } } }, align 8
; Function Attrs: uwtable
define internal void @_ZN17extend_from_slice13test_extend_217hf0b9fd26aa755952E(%"test::Bencher"* nocapture dereferenceable(32)) unnamed_addr #0 personality i32 (i32, i32, i64, %"unwind::libunwind::_Unwind_Exception"*, %"unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality {
bb2:
%dummy.i.i = alloca {}, align 8
%start1.i = alloca %"std::time::Instant", align 8
%tmp_ret2.i = alloca %"std::time::duration::Duration", align 8
%data = alloca [16 x i8], align 1
%data32 = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 0
call void @llvm.lifetime.start(i64 16, i8* %data32)
call void @llvm.memset.p0i8.i64(i8* %data32, i8 1, i64 16, i32 1, i1 false)
%1 = bitcast %"std::time::duration::Duration"* %tmp_ret2.i to i8*
call void @llvm.lifetime.start(i64 16, i8* %1)
%2 = bitcast %"std::time::Instant"* %start1.i to i8*
call void @llvm.lifetime.start(i64 16, i8* %2), !noalias !1
call void @_ZN3std4time7Instant3now17h087888871b84b0dcE(%"std::time::Instant"* noalias nocapture nonnull sret dereferenceable(16) %start1.i)
%3 = getelementptr inbounds %"test::Bencher", %"test::Bencher"* %0, i64 0, i32 0
%4 = load i64, i64* %3, align 8, !noalias !1
%5 = icmp eq i64 %4, 0
br i1 %5, label %bb8.i, label %bb7.lr.ph.i
bb1: ; preds = %bb6.i.i.i.i19, %bb5
resume { i8*, i32 } %13
bb3: ; preds = %bb8.i
%6 = getelementptr inbounds %"std::time::duration::Duration", %"std::time::duration::Duration"* %tmp_ret2.i, i64 0, i32 0
%7 = getelementptr inbounds %"std::time::duration::Duration", %"std::time::duration::Duration"* %tmp_ret2.i, i64 0, i32 1
%8 = load i64, i64* %6, align 8, !noalias !1
%9 = load i32, i32* %7, align 8, !noalias !1
%10 = getelementptr inbounds %"test::Bencher", %"test::Bencher"* %0, i64 0, i32 1, i32 0
store i64 %8, i64* %10, align 8, !noalias !1
%11 = getelementptr inbounds %"test::Bencher", %"test::Bencher"* %0, i64 0, i32 1, i32 1
store i32 %9, i32* %11, align 4, !noalias !1
call void @llvm.lifetime.end(i64 16, i8* %2), !noalias !1
call void @llvm.lifetime.end(i64 16, i8* %1)
call void @llvm.lifetime.end(i64 16, i8* %data32)
%not..i.i.i.i = icmp eq i64 %v.sroa.8.3, 0
br i1 %not..i.i.i.i, label %bb4, label %bb6.i.i.i.i
bb6.i.i.i.i: ; preds = %bb3
%12 = inttoptr i64 %v.sroa.0.3 to i8*
call void @__rust_deallocate(i8* %12, i64 %v.sroa.8.3, i64 1) #2
br label %bb4
bb4: ; preds = %bb6.i.i.i.i, %bb3
ret void
bb5: ; preds = %bb17.i.i.i.i.i, %bb8.i
%v.sroa.8.0 = phi i64 [ %v.sroa.8.3, %bb8.i ], [ %v.sroa.8.1, %bb17.i.i.i.i.i ]
%v.sroa.0.0 = phi i64 [ %v.sroa.0.3, %bb8.i ], [ %v.sroa.0.1, %bb17.i.i.i.i.i ]
%13 = landingpad { i8*, i32 }
cleanup
%not..i.i.i.i18 = icmp eq i64 %v.sroa.8.0, 0
br i1 %not..i.i.i.i18, label %bb1, label %bb6.i.i.i.i19
bb6.i.i.i.i19: ; preds = %bb5
%14 = inttoptr i64 %v.sroa.0.0 to i8*
call void @__rust_deallocate(i8* %14, i64 %v.sroa.8.0, i64 1) #2
br label %bb1
bb7.lr.ph.i: ; preds = %bb2
%iterator.sroa.0.0.i.in.ptr.1.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 1
%iterator.sroa.0.0.i.in.ptr.2.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 2
%iterator.sroa.0.0.i.in.ptr.3.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 3
%iterator.sroa.0.0.i.in.ptr.4.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 4
%iterator.sroa.0.0.i.in.ptr.5.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 5
%iterator.sroa.0.0.i.in.ptr.6.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 6
%iterator.sroa.0.0.i.in.ptr.7.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 7
%iterator.sroa.0.0.i.in.ptr.8.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 8
%iterator.sroa.0.0.i.in.ptr.9.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 9
%iterator.sroa.0.0.i.in.ptr.10.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 10
%iterator.sroa.0.0.i.in.ptr.11.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 11
%iterator.sroa.0.0.i.in.ptr.12.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 12
%iterator.sroa.0.0.i.in.ptr.13.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 13
%iterator.sroa.0.0.i.in.ptr.14.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 14
%iterator.sroa.0.0.i.in.ptr.15.i.i = getelementptr inbounds [16 x i8], [16 x i8]* %data, i64 0, i64 15
%15 = bitcast {}* %dummy.i.i to i8*
br label %bb7.i
bb7.i: ; preds = %"_ZN17extend_from_slice13test_extend_228_$u7b$$u7b$closure$u7d$$u7d$17h5dd836808a5f99e8E.exit.i", %bb7.lr.ph.i
%v.sroa.8.1 = phi i64 [ 0, %bb7.lr.ph.i ], [ %v.sroa.8.2, %"_ZN17extend_from_slice13test_extend_228_$u7b$$u7b$closure$u7d$$u7d$17h5dd836808a5f99e8E.exit.i" ]
%v.sroa.0.1 = phi i64 [ 1, %bb7.lr.ph.i ], [ %v.sroa.0.2, %"_ZN17extend_from_slice13test_extend_228_$u7b$$u7b$closure$u7d$$u7d$17h5dd836808a5f99e8E.exit.i" ]
%iter.sroa.0.021.i = phi i64 [ 0, %bb7.lr.ph.i ], [ %16, %"_ZN17extend_from_slice13test_extend_228_$u7b$$u7b$closure$u7d$$u7d$17h5dd836808a5f99e8E.exit.i" ]
%16 = add nuw i64 %iter.sroa.0.021.i, 1
%17 = icmp ult i64 %v.sroa.8.1, 16
br i1 %17, label %"_ZN40_$LT$alloc..raw_vec..RawVec$LT$T$GT$$GT$18amortized_new_size17h5fe1fd489c83166aE.exit.i.i.i.i.i", label %bb4.bb9_crit_edge.i.i.i
bb4.bb9_crit_edge.i.i.i: ; preds = %bb7.i
%18 = inttoptr i64 %v.sroa.0.1 to i8*
br label %"_ZN17extend_from_slice13test_extend_228_$u7b$$u7b$closure$u7d$$u7d$17h5dd836808a5f99e8E.exit.i"
"_ZN40_$LT$alloc..raw_vec..RawVec$LT$T$GT$$GT$18amortized_new_size17h5fe1fd489c83166aE.exit.i.i.i.i.i": ; preds = %bb7.i
%19 = shl i64 %v.sroa.8.1, 1
%20 = icmp ugt i64 %19, 16
%_0.0.sroa.speculated.i.i.i.i.i.i.i = select i1 %20, i64 %19, i64 16
%21 = icmp eq i64 %v.sroa.8.1, 0
br i1 %21, label %bb10.i.i.i.i.i, label %bb11.i.i.i.i.i
bb10.i.i.i.i.i: ; preds = %"_ZN40_$LT$alloc..raw_vec..RawVec$LT$T$GT$$GT$18amortized_new_size17h5fe1fd489c83166aE.exit.i.i.i.i.i"
%22 = call i8* @__rust_allocate(i64 %_0.0.sroa.speculated.i.i.i.i.i.i.i, i64 1) #2, !noalias !4
br label %bb15.i.i.i.i.i
bb11.i.i.i.i.i: ; preds = %"_ZN40_$LT$alloc..raw_vec..RawVec$LT$T$GT$$GT$18amortized_new_size17h5fe1fd489c83166aE.exit.i.i.i.i.i"
%23 = inttoptr i64 %v.sroa.0.1 to i8*
%24 = call i8* @__rust_reallocate(i8* %23, i64 %v.sroa.8.1, i64 %_0.0.sroa.speculated.i.i.i.i.i.i.i, i64 1) #2, !noalias !4
br label %bb15.i.i.i.i.i
bb15.i.i.i.i.i: ; preds = %bb11.i.i.i.i.i, %bb10.i.i.i.i.i
%ptr.0.i.i.i.i.i = phi i8* [ %22, %bb10.i.i.i.i.i ], [ %24, %bb11.i.i.i.i.i ]
%25 = icmp eq i8* %ptr.0.i.i.i.i.i, null
br i1 %25, label %bb17.i.i.i.i.i, label %bb18.i.i.i.i.i
bb17.i.i.i.i.i: ; preds = %bb15.i.i.i.i.i
invoke void @_ZN5alloc3oom3oom17he12d244509df7328E()
to label %.noexc16 unwind label %bb5
.noexc16: ; preds = %bb17.i.i.i.i.i
unreachable
bb18.i.i.i.i.i: ; preds = %bb15.i.i.i.i.i
%26 = ptrtoint i8* %ptr.0.i.i.i.i.i to i64
br label %"_ZN17extend_from_slice13test_extend_228_$u7b$$u7b$closure$u7d$$u7d$17h5dd836808a5f99e8E.exit.i"
"_ZN17extend_from_slice13test_extend_228_$u7b$$u7b$closure$u7d$$u7d$17h5dd836808a5f99e8E.exit.i": ; preds = %bb18.i.i.i.i.i, %bb4.bb9_crit_edge.i.i.i
%v.sroa.8.2 = phi i64 [ %_0.0.sroa.speculated.i.i.i.i.i.i.i, %bb18.i.i.i.i.i ], [ %v.sroa.8.1, %bb4.bb9_crit_edge.i.i.i ]
%v.sroa.0.2 = phi i64 [ %26, %bb18.i.i.i.i.i ], [ %v.sroa.0.1, %bb4.bb9_crit_edge.i.i.i ]
%27 = phi i8* [ %ptr.0.i.i.i.i.i, %bb18.i.i.i.i.i ], [ %18, %bb4.bb9_crit_edge.i.i.i ]
%.val.i.i.i.i.i.i = load i8, i8* %data32, align 1, !noalias !4
store i8 %.val.i.i.i.i.i.i, i8* %27, align 1, !noalias !4
%28 = getelementptr inbounds i8, i8* %27, i64 1
%.val.i.i.i.i.1.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.1.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.1.i.i, i8* %28, align 1, !noalias !4
%29 = getelementptr inbounds i8, i8* %27, i64 2
%.val.i.i.i.i.2.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.2.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.2.i.i, i8* %29, align 1, !noalias !4
%30 = getelementptr inbounds i8, i8* %27, i64 3
%.val.i.i.i.i.3.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.3.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.3.i.i, i8* %30, align 1, !noalias !4
%31 = getelementptr inbounds i8, i8* %27, i64 4
%.val.i.i.i.i.4.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.4.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.4.i.i, i8* %31, align 1, !noalias !4
%32 = getelementptr inbounds i8, i8* %27, i64 5
%.val.i.i.i.i.5.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.5.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.5.i.i, i8* %32, align 1, !noalias !4
%33 = getelementptr inbounds i8, i8* %27, i64 6
%.val.i.i.i.i.6.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.6.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.6.i.i, i8* %33, align 1, !noalias !4
%34 = getelementptr inbounds i8, i8* %27, i64 7
%.val.i.i.i.i.7.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.7.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.7.i.i, i8* %34, align 1, !noalias !4
%35 = getelementptr inbounds i8, i8* %27, i64 8
%.val.i.i.i.i.8.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.8.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.8.i.i, i8* %35, align 1, !noalias !4
%36 = getelementptr inbounds i8, i8* %27, i64 9
%.val.i.i.i.i.9.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.9.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.9.i.i, i8* %36, align 1, !noalias !4
%37 = getelementptr inbounds i8, i8* %27, i64 10
%.val.i.i.i.i.10.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.10.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.10.i.i, i8* %37, align 1, !noalias !4
%38 = getelementptr inbounds i8, i8* %27, i64 11
%.val.i.i.i.i.11.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.11.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.11.i.i, i8* %38, align 1, !noalias !4
%39 = getelementptr inbounds i8, i8* %27, i64 12
%.val.i.i.i.i.12.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.12.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.12.i.i, i8* %39, align 1, !noalias !4
%40 = getelementptr inbounds i8, i8* %27, i64 13
%.val.i.i.i.i.13.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.13.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.13.i.i, i8* %40, align 1, !noalias !4
%41 = getelementptr inbounds i8, i8* %27, i64 14
%.val.i.i.i.i.14.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.14.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.14.i.i, i8* %41, align 1, !noalias !4
%42 = getelementptr inbounds i8, i8* %27, i64 15
%.val.i.i.i.i.15.i.i = load i8, i8* %iterator.sroa.0.0.i.in.ptr.15.i.i, align 1, !noalias !4
store i8 %.val.i.i.i.i.15.i.i, i8* %42, align 1, !noalias !4
call void @llvm.lifetime.start(i64 0, i8* %15), !noalias !1
call void asm "", "r,~{dirflag},~{fpsr},~{flags}"({}* nonnull %dummy.i.i) #2, !noalias !1, !srcloc !7
call void @llvm.lifetime.end(i64 0, i8* %15), !noalias !1
%43 = icmp ult i64 %16, %4
br i1 %43, label %bb7.i, label %bb8.i.loopexit
bb8.i.loopexit: ; preds = %"_ZN17extend_from_slice13test_extend_228_$u7b$$u7b$closure$u7d$$u7d$17h5dd836808a5f99e8E.exit.i"
br label %bb8.i
bb8.i: ; preds = %bb8.i.loopexit, %bb2
%v.sroa.8.3 = phi i64 [ 0, %bb2 ], [ %v.sroa.8.2, %bb8.i.loopexit ]
%v.sroa.0.3 = phi i64 [ 1, %bb2 ], [ %v.sroa.0.2, %bb8.i.loopexit ]
invoke void @_ZN3std4time7Instant7elapsed17h8059c91847e86c7cE(%"std::time::duration::Duration"* noalias nocapture nonnull sret dereferenceable(16) %tmp_ret2.i, %"std::time::Instant"* noalias nonnull readonly dereferenceable(16) %start1.i)
to label %bb3 unwind label %bb5
}
; Function Attrs: uwtable
define internal void @_ZN17extend_from_slice6__test4main17h248e5609cd701fcaE() unnamed_addr #0 {
entry-block:
tail call void @_ZN4test16test_main_static17h006f5c91aa4b9d9eE(%"test::TestDescAndFn"* noalias nonnull readonly bitcast ({ { { { i64, %str_slice, [8 x i8] }, i1, [7 x i8], { i64, [16 x i8] } }, { i64, void (%"test::Bencher"*)*, [8 x i8] } } }* @ref.5 to %"test::TestDescAndFn"*), i64 1)
ret void
}
; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.start(i64, i8* nocapture) #1
; Function Attrs: nounwind
declare i32 @rust_eh_personality(i32, i32, i64, %"unwind::libunwind::_Unwind_Exception"*, %"unwind::libunwind::_Unwind_Context"*) unnamed_addr #2
; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.end(i64, i8* nocapture) #1
; Function Attrs: cold noinline noreturn
declare void @_ZN5alloc3oom3oom17he12d244509df7328E() unnamed_addr #3
declare void @_ZN3std4time7Instant3now17h087888871b84b0dcE(%"std::time::Instant"* noalias nocapture sret dereferenceable(16)) unnamed_addr
declare void @_ZN3std4time7Instant7elapsed17h8059c91847e86c7cE(%"std::time::duration::Duration"* noalias nocapture sret dereferenceable(16), %"std::time::Instant"* noalias readonly dereferenceable(16)) unnamed_addr
; Function Attrs: nounwind
declare void @__rust_deallocate(i8*, i64, i64) unnamed_addr #2
; Function Attrs: nounwind
declare i8* @__rust_reallocate(i8*, i64, i64, i64) unnamed_addr #2
; Function Attrs: nounwind
declare noalias i8* @__rust_allocate(i64, i64) unnamed_addr #2
declare void @_ZN4test16test_main_static17h006f5c91aa4b9d9eE(%"test::TestDescAndFn"* noalias nonnull readonly, i64) unnamed_addr
define i64 @main(i64, i8**) unnamed_addr {
top:
%2 = tail call i64 @_ZN3std2rt10lang_start17h5d71a3afaaa4b2ffE(i8* bitcast (void ()* @_ZN17extend_from_slice6__test4main17h248e5609cd701fcaE to i8*), i64 %0, i8** %1)
ret i64 %2
}
declare i64 @_ZN3std2rt10lang_start17h5d71a3afaaa4b2ffE(i8*, i64, i8**) unnamed_addr
; Function Attrs: argmemonly nounwind
declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i32, i1) #1
attributes #0 = { uwtable }
attributes #1 = { argmemonly nounwind }
attributes #2 = { nounwind }
attributes #3 = { cold noinline noreturn }
!llvm.module.flags = !{!0}
!0 = !{i32 1, !"PIE Level", i32 2}
!1 = !{!2}
!2 = distinct !{!2, !3, !"_ZN4test7Bencher4iter17h3e7cf6f397af793fE: argument 0"}
!3 = distinct !{!3, !"_ZN4test7Bencher4iter17h3e7cf6f397af793fE"}
!4 = !{!5, !2}
!5 = distinct !{!5, !6, !"_ZN89_$LT$collections..vec..Vec$LT$T$GT$$u20$as$u20$extend_from_slice..SpecExtend$LT$I$GT$$GT$11spec_extend17h31cda6b6ff1b3740E: argument 0"}
!6 = distinct !{!6, !"_ZN89_$LT$collections..vec..Vec$LT$T$GT$$u20$as$u20$extend_from_slice..SpecExtend$LT$I$GT$$GT$11spec_extend17h31cda6b6ff1b3740E"}
!7 = !{i32 197}
#![feature(test)]
extern crate test;
use test::Bencher;
use std::ptr;
trait SpecExtend<I> {
fn spec_extend(&mut self, iter: I);
}
impl<I, T> SpecExtend<I> for Vec<T>
where I: Iterator<Item=T>,
{
// This is the case for a TrustedLen iterator.
fn spec_extend(&mut self, mut iterator: I) {
let (_, high) = iterator.size_hint();
// None => capacity overflow
let additional = high.unwrap_or(!0);
self.reserve(additional);
unsafe {
let new_len = self.len() + additional; // simplified length handling, not ready for panics
let mut ptr = self.as_mut_ptr().offset(self.len() as isize);
while let Some(element) = iterator.next() {
ptr::write(ptr, element);
ptr = ptr.offset(1);
}
self.set_len(new_len);
}
}
}
#[bench]
fn test_extend_2(b: &mut Bencher) {
let mut v = vec![0u8; 0];
let data = [1; 16];
b.iter(|| {
v.clear();
v.spec_extend(data.iter().cloned());
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment