Skip to content

Don't use QDate/QTime::fromString() with a string format arg

Ahmad Samir requested to merge work/ahmad/parsedatetime into master

Using QDate/QTime::fromString() with format being a string (e.g. "yyyyMMdd" or "hhmmss" respectively) is slower than using a specific form e.g. Qt::ISODate, looking at the upstream code, I think it does a lot of work to figure out the format. So, instead parse the string manually, since we already know what the input is supposed to look like. Profiled using Hotspot, and the expensive QDateTimeParser calls are gone in VCardTool.

When there is no year (string starting with "--"), setting the year to -1 is equivalent to:

date = QDate::fromString(dateString, QStringLiteral("MMdd"));
date = date.addYears(-1900);

this is more straight forward and all unit tests still pass.

Edited by Ahmad Samir

Merge request reports