Thanks for your replies.
It probably doesn't matter at all, because the only result will be that the library is a few micro seconds faster at runtime / at load time.
The reason is probably rather a psychological one than a real performance issue. -- I'd like to write clean code, use the ideal way and don't want to see warnings when running i.e. clazy on my code. When looking at performance there are probably other issues that have a greater impact on the performance.
I actually tested it now:
Test 1: Runtime usage #include <QString> const char *xmlns = "urn:ietf:xml:ns:xmpp-sasl"; // OR: const QString xmlns = QStringLiteral("urn:ietf:xml:ns:xmpp-sasl"); int main() { for (int i = 0; i < 1e9; i++) { // Option A: QString text(xmlns); // Option B: appending 'a' QString xmlnsPlusA = QString(xmlns) + 'a'; } } QStringLiteral char* A: QString( ), QStringLiteral is implicitly-shared 0.5 s 52 s B: appending 'a' 27 s 91 s-> The relative difference is high, but the absolute numbers are not relevant: You need to convert about 500 kB (about 20k comparable strings), so that this takes more than 1 ms and gets a performance problem in a GUI application.
Test 2: Start-up timeI also created a test binary with 10k global static constants (all with the same content):
QString (cast from char *) QStringLiteral char * compile time 3 s 3.5 min < 1 s binary size (stripped) 410 kB 1270 kB 320 kB time to run (10k times) 33 s 23 s 19 sI guess the QStringLiteral binary takes longer to run, because it is larger and only partially, because of the non-POD CTORs.
-> Using QStringLiteral has a slightly larger impact on the execution time than I've expected, but this is still not relevant since you usually have less than 10k global static strings and you only load the binary once instead of 10000 times. As long as you're not developing for an arduino this has probably no relevance.
As expected the usage of QStringLiteral makes the binary a bit larger, the start-up time a little little bit larger, but is faster compared to casting from ascii everytime at runtime.
I'll see if I can do anything with QArrayData, not because it's important, just for fun.