mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user