1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-16 04:42:53 +08:00

QMap cell reference cache only makes code slower (#358)

Benchmarking shows code is slower with it,
it's faster to just create the string.
This commit is contained in:
Daniel Nicoletti 2024-09-02 11:01:14 -03:00 committed by GitHub
parent 11bafef832
commit ee6b265b07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -26,23 +26,16 @@ int intPow(int x, int p)
QString col_to_name(int col_num)
{
static thread_local QMap<int, QString> col_cache;
auto it = col_cache.find(col_num);
if (it == col_cache.end()) {
QString col_str;
int remainder;
while (col_num) {
remainder = col_num % 26;
if (remainder == 0)
remainder = 26;
col_str.prepend(QChar('A' + remainder - 1));
col_num = (col_num - 1) / 26;
}
it = col_cache.insert(col_num, col_str);
QString col_str;
int remainder;
while (col_num) {
remainder = col_num % 26;
if (remainder == 0)
remainder = 26;
col_str.prepend(QChar('A' + remainder - 1));
col_num = (col_num - 1) / 26;
}
return it.value();
return col_str;
}
int col_from_name(const QString &col_str)
@ -104,7 +97,7 @@ CellReference::CellReference(const char *cell)
void CellReference::init(const QString &cell_str)
{
static thread_local QRegularExpression re(QStringLiteral("^\\$?([A-Z]{1,3})\\$?(\\d+)$"));
static const QRegularExpression re(QStringLiteral("^\\$?([A-Z]{1,3})\\$?(\\d+)$"));
QRegularExpressionMatch match = re.match(cell_str);
if (match.hasMatch()) {
const QString col_str = match.captured(1);
@ -138,7 +131,7 @@ CellReference::~CellReference()
QString CellReference::toString(bool row_abs, bool col_abs) const
{
if (!isValid())
return QString();
return {};
QString cell_str;
if (col_abs)