Skip to content

Commit 1d7d256

Browse files
committed
perf(avl_array): iterator find() performance slightly improved as well
1 parent b4aeed9 commit 1d7d256

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

avl_array.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,16 @@ class avl_array
304304
*/
305305
inline iterator find(const key_type& key)
306306
{
307-
for (size_type i = root_; i != INVALID_IDX; i = (key < key_[i]) ? child_[i].left : child_[i].right) {
308-
if (key == key_[i]) {
307+
for (size_type i = root_; i != INVALID_IDX;) {
308+
if (key < key_[i]) {
309+
i = child_[i].left;
310+
} else if (key == key_[i]) {
309311
// found key
310312
return iterator(this, i);
311313
}
314+
else {
315+
i = child_[i].right;
316+
}
312317
}
313318
// key not found, return end() iterator
314319
return end();

0 commit comments

Comments
 (0)