Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S-Expression: Minimize lag when parsing level names #3103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/supertux/level_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ LevelParser::get_level_name(const std::string& filename)
try
{
register_translation_directory(filename);
auto doc = ReaderDocument::from_file(filename);
auto doc = ReaderDocument::from_file(filename, 1);
auto root = doc.get_root();

if (root.get_name() != "supertux-level") {
Expand Down
15 changes: 11 additions & 4 deletions src/util/reader_document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@
#include "util/log.hpp"

ReaderDocument
ReaderDocument::from_stream(std::istream& stream, const std::string& filename)
ReaderDocument::from_string(const std::string& string, const std::string& filename, int depth)
{
sexp::Value sx = sexp::Parser::from_stream(stream, sexp::Parser::USE_ARRAYS);
std::istringstream stream(string);
return from_stream(stream, filename, depth);
}

ReaderDocument
ReaderDocument::from_stream(std::istream& stream, const std::string& filename, int depth)
{
sexp::Value sx = sexp::Parser::from_stream(stream, sexp::Parser::USE_ARRAYS, depth);
return ReaderDocument(filename, std::move(sx));
}

ReaderDocument
ReaderDocument::from_file(const std::string& filename)
ReaderDocument::from_file(const std::string& filename, int depth)
{
log_debug << "ReaderDocument::parse: " << filename << std::endl;

Expand All @@ -41,7 +48,7 @@ ReaderDocument::from_file(const std::string& filename)
msg << "Parser problem: Couldn't open file '" << filename << "'.";
throw std::runtime_error(msg.str());
} else {
return from_stream(in, filename);
return from_stream(in, filename, depth);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/util/reader_document.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
class ReaderDocument final
{
public:
static ReaderDocument from_stream(std::istream& stream, const std::string& filename = "<stream>");
static ReaderDocument from_file(const std::string& filename);
static ReaderDocument from_string(const std::string& string, const std::string& filename = "<string>", int depth = -1);
static ReaderDocument from_stream(std::istream& stream, const std::string& filename = "<stream>", int depth = -1);
static ReaderDocument from_file(const std::string& filename, int depth = -1);

public:
ReaderDocument(const std::string& filename, sexp::Value sx);
Expand Down
6 changes: 1 addition & 5 deletions src/util/reader_mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ ReaderMapping::get(const char* key, std::string& value, const std::optional<cons
if (item[1].is_string()) {
value = item[1].as_string();
return true;
} else if (item[1].is_array() &&
item[1].as_array().size() == 2 &&
item[1].as_array()[0].is_symbol() &&
item[1].as_array()[0].as_string() == "_" &&
item[1].as_array()[1].is_string()) {
} else if (item[1].is_translatable_string()) {
if (s_translations_enabled) {
value = _(item[1].as_array()[1].as_string());
} else {
Expand Down
Loading