From c546dc6090116eeed16232f05c2b4f67eecf0d66 Mon Sep 17 00:00:00 2001 From: Marco Paland Date: Tue, 7 Nov 2017 17:22:37 +0100 Subject: [PATCH] perf(avl_array): find() performance slightly improved --- avl_array.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/avl_array.h b/avl_array.h index fd301a0..562ea01 100644 --- a/avl_array.h +++ b/avl_array.h @@ -279,12 +279,18 @@ class avl_array */ inline bool find(const key_type& key, value_type& val) const { - for (size_type i = root_; i != INVALID_IDX; i = (key < key_[i]) ? child_[i].left : child_[i].right) { - if (key == key_[i]) { + for (size_type i = root_; i != INVALID_IDX;) { + if (key < key_[i]) { + i = child_[i].left; + } + else if (key == key_[i]) { // found key val = val_[i]; return true; } + else { + i = child_[i].right; + } } // key not found return false;