Skip to content

Commit

Permalink
Optimize expensive get_imported_functions_size function.
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed Oct 23, 2024
1 parent a45ee4e commit 20143cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions include/eosio/vm/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,10 @@ namespace eosio { namespace vm {
template<typename Imports>
static uint32_t get_imported_functions_size_impl(const Imports& imports) {
uint32_t number_of_imports = 0;
for (uint32_t i = 0; i < imports.size(); i++) {
if (imports[i].kind == external_kind::Function)
const auto sz = imports.size();
const auto data = imports.data(); // to avoid the unnecessary size check since we iterate from 0 to sz
for (uint32_t i = 0; i < sz; i++) {
if (data[i].kind == external_kind::Function)
number_of_imports++;
}
return number_of_imports;
Expand Down
2 changes: 1 addition & 1 deletion include/eosio/vm/wasm_stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace eosio { namespace vm {
if (_index >= _store.size())
_store.resize(_store.size()*2);
}
_store[_index++] = std::forward<ElemT>(e);
_store[_index++] = std::move(e);
}

ElemT pop() { return _store[--_index]; }
Expand Down

0 comments on commit 20143cb

Please sign in to comment.