Skip to content

Commit f504a70

Browse files
authored
Merge pull request #541 from garethsb/bugfix/lazy-json-schemas
Initialize JSON schemas lazily on first use
2 parents 39c38b6 + 85c746b commit f504a70

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎Development/nmos/json_schema.cpp‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,12 @@ namespace nmos
536536
return result;
537537
}
538538

539-
static std::map<web::uri, web::json::value> schemas = make_schemas();
539+
// built on first use so that loading the library doesn't parse JSON during static initialization
540+
static const std::map<web::uri, web::json::value>& schemas()
541+
{
542+
static const std::map<web::uri, web::json::value> instance = make_schemas();
543+
return instance;
544+
}
540545
}
541546

542547
namespace experimental
@@ -676,9 +681,11 @@ namespace nmos
676681
// load the json schema for the specified base URI
677682
web::json::value load_json_schema(const web::uri& id)
678683
{
679-
auto found = nmos::details::schemas.find(id);
684+
const auto& schemas = nmos::details::schemas();
685+
686+
auto found = schemas.find(id);
680687

681-
if (nmos::details::schemas.end() == found)
688+
if (schemas.end() == found)
682689
{
683690
throw web::json::json_exception((_XPLATSTR("schema not found for ") + id.to_string()).c_str());
684691
}

0 commit comments

Comments
 (0)