mirror of
https://github.com/QtExcel/QXlsx.git
synced 2025-01-30 05:02:52 +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:
parent
11bafef832
commit
ee6b265b07
@ -26,23 +26,16 @@ int intPow(int x, int p)
|
|||||||
|
|
||||||
QString col_to_name(int col_num)
|
QString col_to_name(int col_num)
|
||||||
{
|
{
|
||||||
static thread_local QMap<int, QString> col_cache;
|
QString col_str;
|
||||||
|
int remainder;
|
||||||
auto it = col_cache.find(col_num);
|
while (col_num) {
|
||||||
if (it == col_cache.end()) {
|
remainder = col_num % 26;
|
||||||
QString col_str;
|
if (remainder == 0)
|
||||||
int remainder;
|
remainder = 26;
|
||||||
while (col_num) {
|
col_str.prepend(QChar('A' + remainder - 1));
|
||||||
remainder = col_num % 26;
|
col_num = (col_num - 1) / 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);
|
|
||||||
}
|
}
|
||||||
|
return col_str;
|
||||||
return it.value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int col_from_name(const QString &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)
|
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);
|
QRegularExpressionMatch match = re.match(cell_str);
|
||||||
if (match.hasMatch()) {
|
if (match.hasMatch()) {
|
||||||
const QString col_str = match.captured(1);
|
const QString col_str = match.captured(1);
|
||||||
@ -138,7 +131,7 @@ CellReference::~CellReference()
|
|||||||
QString CellReference::toString(bool row_abs, bool col_abs) const
|
QString CellReference::toString(bool row_abs, bool col_abs) const
|
||||||
{
|
{
|
||||||
if (!isValid())
|
if (!isValid())
|
||||||
return QString();
|
return {};
|
||||||
|
|
||||||
QString cell_str;
|
QString cell_str;
|
||||||
if (col_abs)
|
if (col_abs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user