summaryrefslogtreecommitdiff
path: root/sc/inc
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2021-11-27 23:55:41 +0100
committerLuboš Luňák <l.lunak@collabora.com>2021-12-05 10:00:43 +0100
commit9e0d471466997fce4b59ac88d6bd8ad0108b8974 (patch)
tree6b95ec7eba463a4bf7f81e357497a99a8556bee7 /sc/inc
parent8206a8ef2fbf2de9cca6fb360707fb9b50e6a92c (diff)
move entire ScTable::ValidQuery() into (Sc)QueryEvaluator
This reduces the number of arguments passed around, removed the need for ValidQueryCache (as the data can be now cached in the class itself), it'll allow even more optimizations, and it also makes the by now rather large (almost 1000 lines) helper class a proper class instead of tons of inline code. Change-Id: I585cf580b3e7b2d4512aa535176e97c0abfd547a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126367 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sc/inc')
-rw-r--r--sc/inc/queryevaluator.hxx123
-rw-r--r--sc/inc/table.hxx17
2 files changed, 125 insertions, 15 deletions
diff --git a/sc/inc/queryevaluator.hxx b/sc/inc/queryevaluator.hxx
new file mode 100644
index 000000000000..3caa1c57dfcf
--- /dev/null
+++ b/sc/inc/queryevaluator.hxx
@@ -0,0 +1,123 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#pragma once
+
+#include <memory>
+#include <vector>
+#include <unordered_map>
+
+#include "queryentry.hxx"
+
+class ScDocument;
+class ScTable;
+struct ScQueryParam;
+class CollatorWrapper;
+struct ScRefCellValue;
+struct ScInterpreterContext;
+
+namespace sc
+{
+class TableColumnBlockPositionSet;
+}
+namespace svl
+{
+class SharedStringPool;
+}
+namespace utl
+{
+class TransliterationWrapper;
+}
+
+class ScQueryEvaluator
+{
+ ScDocument& mrDoc;
+ svl::SharedStringPool& mrStrPool;
+ const ScTable& mrTab;
+ const ScQueryParam& mrParam;
+ bool* mpTestEqualCondition;
+ utl::TransliterationWrapper* mpTransliteration;
+ CollatorWrapper* mpCollator;
+ const bool mbMatchWholeCell;
+ const bool mbCaseSensitive;
+ const ScInterpreterContext* mpContext;
+
+ const SCSIZE mnEntryCount;
+ bool* mpPasst;
+ bool* mpTest;
+ static constexpr SCSIZE nFixedBools = 32;
+ bool maBool[nFixedBools];
+ bool maTest[nFixedBools];
+ std::unique_ptr<bool[]> mpBoolDynamic;
+ std::unique_ptr<bool[]> mpTestDynamic;
+
+ std::unordered_map<FormulaError, svl::SharedString> mCachedSharedErrorStrings;
+ std::vector<double> mCachedSortedItemValues;
+ std::vector<const rtl_uString*> mCachedSortedItemStrings;
+ bool mCachedSortedItemValuesReady = false;
+ bool mCachedSortedItemStringsReady = false;
+
+ static bool isPartialTextMatchOp(const ScQueryEntry& rEntry);
+ static bool isTextMatchOp(const ScQueryEntry& rEntry);
+ void setupTransliteratorIfNeeded();
+ void setupCollatorIfNeeded();
+
+ bool isRealWildOrRegExp(const ScQueryEntry& rEntry) const;
+ bool isTestWildOrRegExp(const ScQueryEntry& rEntry) const;
+ static bool isQueryByValue(const ScQueryEntry::Item& rItem, const ScRefCellValue& rCell);
+ static bool isQueryByValueForCell(const ScRefCellValue& rCell);
+ static bool isQueryByString(const ScQueryEntry& rEntry, const ScQueryEntry::Item& rItem,
+ const ScRefCellValue& rCell);
+
+ sal_uInt32 getNumFmt(SCCOL nCol, SCROW nRow);
+
+ std::pair<bool, bool> compareByValue(const ScRefCellValue& rCell, SCCOL nCol, SCROW nRow,
+ const ScQueryEntry& rEntry,
+ const ScQueryEntry::Item& rItem);
+
+ OUString getCellString(const ScRefCellValue& rCell, SCROW nRow, const ScQueryEntry& rEntry,
+ const svl::SharedString** sharedString);
+
+ bool isFastCompareByString(const ScQueryEntry& rEntry) const;
+ template <bool bFast = false>
+ std::pair<bool, bool>
+ compareByString(const ScQueryEntry& rEntry, const ScQueryEntry::Item& rItem,
+ const svl::SharedString* pValueSource1, const OUString* pValueSource2);
+ std::pair<bool, bool> compareByTextColor(SCCOL nCol, SCROW nRow,
+ const ScQueryEntry::Item& rItem);
+ std::pair<bool, bool> compareByBackgroundColor(SCCOL nCol, SCROW nRow,
+ const ScQueryEntry::Item& rItem);
+
+ static std::pair<bool, bool> compareByRangeLookup(const ScRefCellValue& rCell,
+ const ScQueryEntry& rEntry,
+ const ScQueryEntry::Item& rItem);
+
+ std::pair<bool, bool> processEntry(SCROW nRow, SCCOL nCol, ScRefCellValue& aCell,
+ const ScQueryEntry& rEntry);
+
+public:
+ ScQueryEvaluator(ScDocument& rDoc, const ScTable& rTab, const ScQueryParam& rParam,
+ const ScInterpreterContext* pContext = nullptr,
+ bool* pTestEqualCondition = nullptr);
+
+ bool ValidQuery(SCROW nRow, const ScRefCellValue* pCell = nullptr,
+ sc::TableColumnBlockPositionSet* pBlockPos = nullptr);
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 0bb6548d5dd9..672d8431dfe4 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -466,6 +466,7 @@ public:
return aCol[rPos.Col()].GetCellType( rPos.Row() );
}
CellType GetCellType( SCCOL nCol, SCROW nRow ) const;
+ ScRefCellValue GetCellValue( SCCOL nCol, sc::ColumnBlockPosition& rBlockPos, SCROW nRow );
ScRefCellValue GetCellValue( SCCOL nCol, SCROW nRow ) const;
void GetFirstDataPos(SCCOL& rCol, SCROW& rRow) const;
@@ -954,21 +955,7 @@ public:
void Reorder( const sc::ReorderParam& rParam );
- // Internal cache that can be repeatedly used for a sequence of related ValidQuery()
- // calls (related meaning done in a loop for the same document and query data).
- struct ValidQueryCache
- {
- std::unordered_map<FormulaError, svl::SharedString> mCachedSharedErrorStrings;
- std::vector<double> mCachedSortedItemValues;
- std::vector<const rtl_uString*> mCachedSortedItemStrings;
- bool mCachedSortedItemValuesReady = false;
- bool mCachedSortedItemStringsReady = false;
- };
- bool ValidQuery(
- SCROW nRow, const ScQueryParam& rQueryParam, const ScRefCellValue* pCell = nullptr,
- bool* pbTestEqualCondition = nullptr, const ScInterpreterContext* pContext = nullptr,
- sc::TableColumnBlockPositionSet* pBlockPos = nullptr,
- ValidQueryCache* pQueryCache = nullptr );
+ // For ValidQuery() see ScQueryEvalutor class.
void TopTenQuery( ScQueryParam& );
void PrepareQuery( ScQueryParam& rQueryParam );
SCSIZE Query(const ScQueryParam& rQueryParam, bool bKeepSub);