Skip to content

Commit

Permalink
Reserve Vector elements instead of resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
skade committed Nov 4, 2015
1 parent 7f53da7 commit 7a97b7d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/output/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ impl<U> Table<U> where U: Users {
// necessary to maintain information about the previously-printed
// lines, as the output will change based on whether the
// *previous* entry was the last in its directory.
stack.resize(row.depth + 1, TreePart::Edge);
stack.reserve(row.depth + 1);
stack[row.depth] = if row.last { TreePart::Corner } else { TreePart::Edge };

This comment has been minimized.

Copy link
@ogham

ogham Nov 4, 2015

Owner

I’d like to think that it only grows the buffer, not shrinking it—I’ll test this before I merge

This comment has been minimized.

Copy link
@ogham

ogham Nov 4, 2015

Owner

Sorry, your code blows up when I try to run it on the files generated by the generate_testcases.sh script:

$ env RUST_BACKTRACE=1 ./target/debug/exa testcases --long --tree
thread '<main>' panicked at 'index out of bounds: the len is 0 but the index is 0', ../src/libcollections/vec.rs:1116
stack backtrace:
   1:        0x10d17bf58 - sys::backtrace::tracing::imp::write::ha1fecc817f4697fas9s
   2:        0x10d17d8ff - panicking::log_panic::_<closure>::closure.39708
   3:        0x10d17d3a2 - panicking::log_panic::h631dc367e76559d1xYw
   4:        0x10d170ad6 - sys_common::unwind::begin_unwind_inner::h7efd836278b7cb4d0cs
   5:        0x10d170ebe - sys_common::unwind::begin_unwind_fmt::hc18453f57d01abac6bs
   6:        0x10d17b5e7 - rust_begin_unwind
   7:        0x10d19eb30 - panicking::panic_fmt::h6c78ce0128588a957HK
   8:        0x10d19b2a0 - panicking::panic_bounds_check::he3d825b7425f1f15dHK
   9:        0x10d06b6a8 - vec::_<impl>::index_mut::index_mut::h10940914251765809645
  10:        0x10d0686b3 - output::details::_<impl>::print_table::h2120631830446409840
  11:        0x10d03b0f2 - output::details::_<impl>::view::hf18e487ba7e765fbgsd
  12:        0x10d076c6a - _<impl>::print_files::h90e22310646e25bcate
  13:        0x10d075c69 - _<impl>::run::h44554560c55db755lle
  14:        0x10d079205 - main::h1e76b862f41d2fecUte
  15:        0x10d17d122 - sys_common::unwind::try::try_fn::h9087674402355109000
  16:        0x10d17b428 - __rust_try
  17:        0x10d17cfc9 - rt::lang_start::h424562221c19d8b9FVw
  18:        0x10d07a959 - main

Changing it back to resize instead of reserve fixes it. Turns out, the row depth can decrease (such as in this case).

This comment has been minimized.

Copy link
@skade

skade Nov 4, 2015

Author Contributor

Ah, I missed that script. I'll see about that.


for i in 1 .. row.depth + 1 {
Expand Down

0 comments on commit 7a97b7d

Please sign in to comment.