fix(library/parray): it is unsafe to return reference

A reroot operation performed by another thread may invalidate the reference.
This commit is contained in:
Leonardo de Moura 2017-05-03 10:02:10 -07:00
parent a8cc5c4e31
commit 2e5702d31e

View file

@ -246,7 +246,7 @@ class parray {
dec_ref(last);
}
static T const & read_aux(cell * c, size_t i) {
static T read_aux(cell * c, size_t i) {
if (c->kind() != Root)
reroot(c);
lean_assert(c->kind() == Root);
@ -254,7 +254,7 @@ class parray {
return c->m_values[i];
}
static T const & read(cell * c, size_t i) {
static T read(cell * c, size_t i) {
if (get_rc(c) == 1 && c->kind() == Root) {
lean_assert(i < c->size());
return c->m_values[i];
@ -454,7 +454,7 @@ public:
return size(m_cell);
}
T const & operator[](size_t i) const {
T operator[](size_t i) const {
return read(m_cell, i);
}