Made value object regular expressions thread safe

(note: which is important because the RegEx is static)
This commit is contained in:
Klaus Basan
2015-07-13 19:32:03 +02:00
committed by Mathew Sutcliffe
parent f8c83ce2a3
commit e3b0720295
3 changed files with 17 additions and 5 deletions

View File

@@ -106,8 +106,11 @@ namespace BlackMisc
bool CAirlineIcaoCode::isValidAirlineDesignator(const QString &airline)
{
static QRegularExpression regexp("^[A-Z]+[A-Z0-9]*$");
if (airline.length() < 2 || airline.length() > 5) return false;
static QThreadStorage<QRegularExpression> tsRegex;
if (! tsRegex.hasLocalData()) { tsRegex.setLocalData(QRegularExpression("^[A-Z]+[A-Z0-9]*$")); }
const QRegularExpression &regexp = tsRegex.localData();
return (regexp.match(airline).hasMatch());
}