Small perfomance optimization in Directives and Tag methods
This commit is contained in:
parent
190ad502b5
commit
56f39208a5
@ -3,15 +3,19 @@
|
|||||||
namespace YAML {
|
namespace YAML {
|
||||||
Directives::Directives() : version{true, 1, 2}, tags{} {}
|
Directives::Directives() : version{true, 1, 2}, tags{} {}
|
||||||
|
|
||||||
const std::string Directives::TranslateTagHandle(
|
std::string Directives::TranslateTagHandle(
|
||||||
const std::string& handle) const {
|
const std::string& handle) const {
|
||||||
|
std::string result;
|
||||||
auto it = tags.find(handle);
|
auto it = tags.find(handle);
|
||||||
if (it == tags.end()) {
|
if (it == tags.end()) {
|
||||||
if (handle == "!!")
|
if (handle == "!!")
|
||||||
return "tag:yaml.org,2002:";
|
result = "tag:yaml.org,2002:";
|
||||||
return handle;
|
else
|
||||||
|
result = handle;
|
||||||
|
} else {
|
||||||
|
result = it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
return it->second;
|
return result;
|
||||||
}
|
}
|
||||||
} // namespace YAML
|
} // namespace YAML
|
||||||
|
|||||||
@ -19,7 +19,7 @@ struct Version {
|
|||||||
struct Directives {
|
struct Directives {
|
||||||
Directives();
|
Directives();
|
||||||
|
|
||||||
const std::string TranslateTagHandle(const std::string& handle) const;
|
std::string TranslateTagHandle(const std::string& handle) const;
|
||||||
|
|
||||||
Version version;
|
Version version;
|
||||||
std::map<std::string, std::string> tags;
|
std::map<std::string, std::string> tags;
|
||||||
|
|||||||
23
src/tag.cpp
23
src/tag.cpp
@ -29,22 +29,31 @@ Tag::Tag(const Token& token)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string Tag::Translate(const Directives& directives) {
|
std::string Tag::Translate(const Directives& directives) {
|
||||||
|
std::string result;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case VERBATIM:
|
case VERBATIM:
|
||||||
return value;
|
result = value;
|
||||||
|
break;
|
||||||
case PRIMARY_HANDLE:
|
case PRIMARY_HANDLE:
|
||||||
return directives.TranslateTagHandle("!") + value;
|
result = directives.TranslateTagHandle("!") + value;
|
||||||
|
break;
|
||||||
case SECONDARY_HANDLE:
|
case SECONDARY_HANDLE:
|
||||||
return directives.TranslateTagHandle("!!") + value;
|
result = directives.TranslateTagHandle("!!") + value;
|
||||||
|
break;
|
||||||
case NAMED_HANDLE:
|
case NAMED_HANDLE:
|
||||||
return directives.TranslateTagHandle("!" + handle + "!") + value;
|
result = directives.TranslateTagHandle("!" + handle + "!") + value;
|
||||||
|
break;
|
||||||
case NON_SPECIFIC:
|
case NON_SPECIFIC:
|
||||||
// TODO:
|
// TODO:
|
||||||
return "!";
|
result = "!";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
|
||||||
throw std::runtime_error("yaml-cpp: internal error, bad tag type");
|
throw std::runtime_error("yaml-cpp: internal error, bad tag type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
} // namespace YAML
|
} // namespace YAML
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user