[JSONSerialization] Introduce ScalarReferenceTraits

For ScalarTraits, a buffer was always created on the heap to which the
scalar string value was written just to be copied to the output buffer
again. In case the value already exists in a memory buffer it is way
cheaper to avoid the heap allocation and copy it straight to the output
buffer.
This commit is contained in:
Alex Hoppen
2018-06-01 13:12:07 -07:00
parent 48eb400a93
commit 07b449bbd5
5 changed files with 117 additions and 31 deletions

View File

@@ -231,18 +231,17 @@ void Output::indent() {
// traits for built-in types
//===----------------------------------------------------------------------===//
void ScalarTraits<bool>::output(const bool &Val, raw_ostream &Out) {
Out << (Val ? "true" : "false");
StringRef ScalarReferenceTraits<bool>::stringRef(const bool &Val) {
return (Val ? "true" : "false");
}
void ScalarTraits<StringRef>::output(const StringRef &Val,
raw_ostream &Out) {
Out << Val;
StringRef ScalarReferenceTraits<StringRef>::stringRef(const StringRef &Val) {
return Val;
}
void ScalarTraits<std::string>::output(const std::string &Val,
raw_ostream &Out) {
Out << Val;
StringRef
ScalarReferenceTraits<std::string>::stringRef(const std::string &Val) {
return Val;
}
void ScalarTraits<uint8_t>::output(const uint8_t &Val,