diff --git a/CHANGES b/CHANGES index 0913976865..9a3392f57b 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,8 @@ +3.2.0-dev.396 | 2020-04-14 15:45:54 -0700 + + * A few minor cleanups in Dict (Tim Wojtulewicz, Corelight) + 3.2.0-dev.394 | 2020-04-14 15:29:00 -0700 * Fix a confusing variable name shadowing (Jon Siwek, Corelight) diff --git a/VERSION b/VERSION index c5ccf9199b..33fab6f2e8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.2.0-dev.394 +3.2.0-dev.396 diff --git a/src/Dict.cc b/src/Dict.cc index 1f62908c5c..2fa2eae0a6 100644 --- a/src/Dict.cc +++ b/src/Dict.cc @@ -270,10 +270,8 @@ void* Dictionary::Lookup(const void* key, int key_size, hash_t hash) const if ( chain ) { - for ( int i = 0; i < chain->length(); ++i ) + for ( const auto& entry : *chain ) { - DictEntry* entry = (*chain)[i]; - if ( entry->hash == hash && entry->len == key_size && ! memcmp(key, entry->key, key_size) ) return entry->value; @@ -336,7 +334,9 @@ void* Dictionary::Remove(const void* key, int key_size, hash_t hash, if ( ! chain ) return nullptr; - for ( int i = 0; i < chain->length(); ++i ) + size_t chain_length = chain->length(); + + for ( auto i = 0u; i < chain_length; ++i ) { DictEntry* entry = (*chain)[i]; @@ -635,7 +635,7 @@ bool Dictionary::IsPrime(int n) const void Dictionary::StartChangeSize(int new_size) { // Only start resizing if there isn't any iteration in progress. - if ( cookies.length() > 0 ) + if ( ! cookies.empty() ) return; if ( tbl2 ) @@ -652,7 +652,7 @@ void Dictionary::StartChangeSize(int new_size) void Dictionary::MoveChains() { // Do not change current distribution if there an ongoing iteration. - if ( cookies.length() > 0 ) + if ( ! cookies.empty() ) return; // Attempt to move this many entries (must do at least 2) @@ -667,9 +667,9 @@ void Dictionary::MoveChains() tbl[tbl_next_ind - 1] = nullptr; - for ( int j = 0; j < chain->length(); ++j ) + for ( const auto& elem : *chain ) { - Insert((*chain)[j], false); + Insert(elem, false); --num_entries; --num; }