Skip to content

Commit

Permalink
Use std::string_view for string literals in JSON serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardodebenedictis committed Jan 15, 2025
1 parent 2376cba commit 49e74a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace riddle
for (const auto &atm : pred.second->get_atoms())
all_atoms.insert(static_cast<atom *>(atm.get()));

json::json j_core{{"name", name}};
json::json j_core{{"name", std::string_view(name)}};
if (!all_items.empty())
{ // we add the items of the core..
json::json j_items;
Expand Down
8 changes: 4 additions & 4 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace riddle
bool_item::bool_item(bool_type &tp) : item(tp) {}
json::json bool_item::to_json() const
{
json::json j_val{{"type", get_type().get_name()}}; // we add the type of the item..
json::json j_val{{"type", std::string_view(get_type().get_name())}}; // we add the type of the item..
switch (get_type().get_scope().get_core().bool_value(*this))
{
case utils::True:
Expand All @@ -26,7 +26,7 @@ namespace riddle
arith_item::arith_item(time_type &tp) : item(tp) {}
json::json arith_item::to_json() const
{
json::json j_val{{"type", get_type().get_name()}}; // we add the type of the item..
json::json j_val{{"type", std::string_view(get_type().get_name())}}; // we add the type of the item..
const auto val = get_type().get_scope().get_core().arith_value(*this);
j_val["num"] = static_cast<int64_t>(val.get_rational().numerator());
j_val["den"] = static_cast<int64_t>(val.get_rational().denominator());
Expand All @@ -37,7 +37,7 @@ namespace riddle
}

string_item::string_item(string_type &tp) : item(tp) {}
json::json string_item::to_json() const { return {{"type", get_type().get_name(), {"val", get_type().get_scope().get_core().string_value(*this)}}}; }
json::json string_item::to_json() const { return {{"type", std::string_view(get_type().get_name()), {"val", get_type().get_scope().get_core().string_value(*this)}}}; }

enum_item::enum_item(type &tp, std::vector<std::reference_wrapper<utils::enum_val>> &&values) : item(tp), values(std::move(values)) {}
json::json enum_item::to_json() const
Expand Down Expand Up @@ -67,7 +67,7 @@ namespace riddle
{
json::json j_itm{{"type", get_type().get_full_name()}}; // we add the type of the item..
#ifdef COMPUTE_NAMES
j_itm["name"] = get_type().get_scope().get_core().guess_name(*this);
j_itm["name"] = std::string_view(get_type().get_scope().get_core().guess_name(*this));
#endif

if (!items.empty())
Expand Down

0 comments on commit 49e74a4

Please sign in to comment.