From 26f80567f12235a2a60671d10e1726aae3fe4f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 26 Nov 2021 15:36:25 +0100 Subject: [PATCH] trie: refactor StackTrie.getDiffIndex() --- trie/stacktrie.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/trie/stacktrie.go b/trie/stacktrie.go index 645f78be6480..76258c31123c 100644 --- a/trie/stacktrie.go +++ b/trie/stacktrie.go @@ -210,10 +210,12 @@ func (st *StackTrie) Reset() { // at which the chunk pointed by st.keyOffset is different from // the same chunk in the full key. func (st *StackTrie) getDiffIndex(key []byte) int { - diffindex := 0 - for ; diffindex < len(st.key) && st.key[diffindex] == key[diffindex]; diffindex++ { + for idx, nibble := range st.key { + if nibble != key[idx] { + return idx + } } - return diffindex + return len(st.key) } // Helper function to that inserts a (key, value) pair into