Clang: Return ClangString instead of Utf8String

Utf8String is allocating memory but for many compares it is not needed.
In an inner loop this can be expensive.

Change-Id: I6320823ab7e086008447eea255e52859a7faaad7
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
Marco Bubke
2017-06-13 16:04:45 +02:00
parent 02194a5542
commit ae485ac551
5 changed files with 58 additions and 22 deletions

View File

@@ -30,6 +30,7 @@
#include <utf8string.h>
#include <cstring>
#include <ostream>
namespace ClangBackEnd {
@@ -85,6 +86,11 @@ public:
return cxString.data == nullptr;
}
bool hasContent() const
{
return !isNull() && std::strlen(cString()) > 0;
}
friend bool operator==(const ClangString &first, const ClangString &second)
{
return std::strcmp(first.cString(), second.cString()) == 0;
@@ -118,6 +124,13 @@ public:
return second == first;
}
friend std::ostream &operator<<(std::ostream &out, const ClangString &string)
{
out << string.cString();
return out;
}
private:
CXString cxString;
};