Skip to content

Commit c546dc6

Browse files
committed
perf(avl_array): find() performance slightly improved
1 parent 5f1d86d commit c546dc6

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

avl_array.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,18 @@ class avl_array
279279
*/
280280
inline bool find(const key_type& key, value_type& val) const
281281
{
282-
for (size_type i = root_; i != INVALID_IDX; i = (key < key_[i]) ? child_[i].left : child_[i].right) {
283-
if (key == key_[i]) {
282+
for (size_type i = root_; i != INVALID_IDX;) {
283+
if (key < key_[i]) {
284+
i = child_[i].left;
285+
}
286+
else if (key == key_[i]) {
284287
// found key
285288
val = val_[i];
286289
return true;
287290
}
291+
else {
292+
i = child_[i].right;
293+
}
288294
}
289295
// key not found
290296
return false;

0 commit comments

Comments
 (0)