Skip to content

Commit ee6b265

Browse files
authored
QMap cell reference cache only makes code slower (#358)
Benchmarking shows code is slower with it, it's faster to just create the string.
1 parent 11bafef commit ee6b265

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

QXlsx/source/xlsxcellreference.cpp

+11-18
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,16 @@ int intPow(int x, int p)
2626

2727
QString col_to_name(int col_num)
2828
{
29-
static thread_local QMap<int, QString> col_cache;
30-
31-
auto it = col_cache.find(col_num);
32-
if (it == col_cache.end()) {
33-
QString col_str;
34-
int remainder;
35-
while (col_num) {
36-
remainder = col_num % 26;
37-
if (remainder == 0)
38-
remainder = 26;
39-
col_str.prepend(QChar('A' + remainder - 1));
40-
col_num = (col_num - 1) / 26;
41-
}
42-
it = col_cache.insert(col_num, col_str);
29+
QString col_str;
30+
int remainder;
31+
while (col_num) {
32+
remainder = col_num % 26;
33+
if (remainder == 0)
34+
remainder = 26;
35+
col_str.prepend(QChar('A' + remainder - 1));
36+
col_num = (col_num - 1) / 26;
4337
}
44-
45-
return it.value();
38+
return col_str;
4639
}
4740

4841
int col_from_name(const QString &col_str)
@@ -104,7 +97,7 @@ CellReference::CellReference(const char *cell)
10497

10598
void CellReference::init(const QString &cell_str)
10699
{
107-
static thread_local QRegularExpression re(QStringLiteral("^\\$?([A-Z]{1,3})\\$?(\\d+)$"));
100+
static const QRegularExpression re(QStringLiteral("^\\$?([A-Z]{1,3})\\$?(\\d+)$"));
108101
QRegularExpressionMatch match = re.match(cell_str);
109102
if (match.hasMatch()) {
110103
const QString col_str = match.captured(1);
@@ -138,7 +131,7 @@ CellReference::~CellReference()
138131
QString CellReference::toString(bool row_abs, bool col_abs) const
139132
{
140133
if (!isValid())
141-
return QString();
134+
return {};
142135

143136
QString cell_str;
144137
if (col_abs)

0 commit comments

Comments
 (0)