Skip to content

Conversation

@helly25
Copy link

@helly25 helly25 commented May 27, 2025

Some tweaks:

  • Make json.h an IWYU import header.
  • Change Reader::parse to take its document parameter as std::string_view.
  • Add static void StreamWriterBuilder::updateDefaults(const Json::Value& settings);
    • Allows to set the global configuration.

* Make `json.h` an IWYU import header.
* Change `Reader::parse` to take its `document` parameter as `std::string_view`.
* Add `static void StreamWriterBuilder::updateDefaults(const Json::Value& settings);`
  * Allows to set the global configuration.
@helly25
Copy link
Author

helly25 commented Jun 6, 2025

@baylesj could you review this?

@baylesj
Copy link
Contributor

baylesj commented Nov 12, 2025

@baylesj could you review this?

Thanks for this patch. I have (obviously) not been super active in this repository as of late but am intending to provide a little bit more active stewardship. I am happy to review.

* error occurred.
*/
bool parse(const std::string& document, Value& root,
bool parse(std::string_view document, Value& root,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This causes a compile time error in the build since we don't support string_view currently. I believe JsonCpp is on C++11? And std::string_view was added in C++17.

We have been talking about a major version change so it's quite possible bumping the standard could be part of that version change. But right now I don't think we can land this specific part of the change unfortunately.

char const* end = begin + doc.size();
// Note that we do not actually need a null-terminator.
CharReaderPtr const reader(fact.newCharReader());
return reader->parse(begin, end, root, errs);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think it's fine to have begin and end inline here:

return reader->parse(doc.data(), doc.data() + doc.size(), root, errs);

Seems clear enough to me.

// static
void StreamWriterBuilder::setDefaults(Json::Value* settings) {

static Json::Value& global_settings_ = *new Json::Value([] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is declaring a new global static, which may have implications for some libraries around storage and memory. For example, in Chrome, global statics like this aren't usually allowed.

Is there a performance or other benefit causing this change? I'm not aware of any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants