]> git.lizzy.rs Git - rust.git/commit
std: Fix iteration over vectors of 0-size values
authorAlex Crichton <alex@alexcrichton.com>
Fri, 11 Apr 2014 21:34:21 +0000 (14:34 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 11 Apr 2014 22:12:56 +0000 (15:12 -0700)
commit7a82d478a3c9301eda4453ec222842f750e13630
tree87675327dc77a289bfd699c5c12f546804fa56d8
parent8b6091e8f1f5531fe907f84b6a2b27af04a95e8f
std: Fix iteration over vectors of 0-size values

Previously, all slices derived from a vector whose values were of size 0 had a
null pointer as the 'data' pointer on the slice. This caused first pointer to be
yielded during iteration to always be the null pointer. Due to the null pointer
optimization, this meant that the first return value was None, instead of
Some(&T).

This commit changes slice construction from a Vec instance to use a base pointer
of 1 if the values have zero size. This means that the iterator will never
return null, and the iteration will proceed appropriately.

Closes #13467
src/libstd/vec.rs