Skip to content

Introduce UniValue::emplace_back() for adding object entries without duplicate key check

This replaces the optional boolean argument of pushKV() to control the duplicate key check.

Rationale:

  • A different method name is easier to read, especially when appending boolean values to UniValue objects.
  • Having different methods enforces a compile-time choice.
  • "boolean in the API are regarded as an antipattern"
  • emplace_back() now works on both UniValue itself as well as UniValue::ObjectEntries (which is an alias for std::vector). This makes it easier to change between both types without changing all the code, like in !663 (merged).
  • In the long run, I think it is likely the duplicate key check is removed completely, and then we don't want to be stuck with the extra false argument everywhere.

The duplicate key check or absence thereof is now also checked in UniValue unit tests.

This MR also removes the private __pushKV() method (in a separate commit). Note that unlike __pushKV(), emplace_back() does check whether the type is VOBJ.

This MR fits in the code quality objective of #51.

Test plan: ninja check-univalue all bench_bitcoin check check-functional

Edited by BigBlockIfTrue

Merge request reports